In PHP, how can I replicate the expand/contract feature for Tinyurls as on search.twitter.com?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The Solution here from @Pons solution, didn't work alone on my php7.3 server reslolving stackexchange URLs like
https://stackoverflow.com/q/62317
This solved it:
Another simple and easy way:
And here is how to contract an arbitrary URL using the TinyURL API. The general call pattern goes like this, it's a simple HTTP request with parameters:
http://tinyurl.com/api-create.php?url=http://insertyourstuffhere.com
This will return the corresponding TinyURL for http://insertyourstuffhere.com. In PHP, you can wrap this in an fsockopen() call or, for convenience, just use the file() function to retrieve it:
If you just want the location, then do a HEAD request instead of GET.
In PHP there is also a get_headers function that can be used to decode tiny urls.
If you want to find out where a tinyurl is going, use fsockopen to get a connection to tinyurl.com on port 80, and send it an HTTP request like this
The response you get back will look like
example code...