Reputation: 17530
i have seen this is Facebook, when the user paste the image link
www.blahblah.blah\blah.jpg
it automatically gets to <img src="...."/>
how to do it in PHP ?
Upvotes: 0
Views: 882
Reputation: 2667
PHP is serve-side so you will need to use a client side technology like Javascript for example.
Update:
But you could send the content to the server and let PHP parse and format. But this depends on you as I don't know if you use Ajax or if you want to this on submit?
You can identify any links with a regular expression and Javascript, which would be listening for textchange. The Javascript would scan the text each time it's changed and you can then turn all the links, e-mails etc. to links instead of text. This will provide a nice effect for your users.
Haven't Implemented this myself, so be sure to test as I don't know how well textchange will perform with actions like paste. Any suggestions for another event?
Upvotes: 0
Reputation: 1598
You're looking for a BBCode-like replacing system. There's plenty of them on the internets. One example: http://snipplr.com/view/2296/php--bbcode/
Upvotes: 1
Reputation: 4241
im not a PHP programmer, but the problem seems easy enough. The general idea (in a non-language specific form) would be:
1. Get user input somewhere into a string (in facebook - post on a wall or some other place)
2. Search the string for the image extension (.jpg, .png, .gif, etc.)
3. If the image extension is found, append the tags to either side of the string appropriately
4. Act further on the event of the image extension being found
Upvotes: 0