2011-04-11 66 views
0

我看这就是Facebook,当用户将图像粘贴链接 www.blahblah.blah \ blah.jpg 它会自动获取到<img src="...."/> 如何做到这一点在PHP?转换到image.jpg的<img src="image.jpg">

+4

只需注意您需要处理用户选择的图像的各种问题,例如,大小,炸毁你的页面,巨大的文件大小加载等 – Kzqai 2011-04-11 14:49:50

+0

[任何preg_match()从文本中提取图像URL的可能的重复?](http://stackoverflow.com/questions/2143202/any-preg-match-从文本中提取图像的URL) – 2011-04-11 14:51:05

+0

不,这不是那个的重复! – Sourav 2011-04-11 14:52:40

回答

0

即时通讯不是PHP程序员,但问题似乎很容易。总体思路(非语言特定形式)为:

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 
0

PHP是服务端,所以你将需要使用像Javascript这样的客户端技术。

更新:

但是你可以将内容发送到服务器,让PHP的解析和格式。但是这取决于你,因为我不知道你是否使用Ajax或者如果你想提交这个?

您可以使用正则表达式和Javascript来识别任何链接,这些链接将监听textchange。 Javascript会在每次更改文本时扫描文本,然后您可以将所有链接,电子邮件等转换为链接而不是文本。这将为您的用户带来不错的效果。

还没有自己实现,所以一定要测试,因为我不知道textchange将如何执行粘贴等操作。任何其他事件的建议?