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
Here is another way to decode short urls via CURL library:
It's described here.
As people have answered programatically how to create and resolve tinyurl.com redirects, I'd like to (strongly) suggest something: caching.
In the twitter example, if every time you clicked the "expand" button, it did an XmlHTTPRequest to, say,
/api/resolve_tinyurl/http://tinyurl.com/abcd
, then the server created a HTTP connection to tinyurl.com, and inspected the header - it would destroy both twitter and tinyurl's servers..An infinitely more sensible method would be to do something like this Python'y pseudo-code..
Where
cache
's items magically get backed up into memory, and/or a file, and query_tinyurl() works as Paul Dixon's answer does.