将image.jpg转换为<img src="image.jpg">


convert image.jpg to <img src="image.jpg">

我看到这是Facebook,当用户粘贴图片链接www.blahblah.blah ' blah.jpg它会自动到达<img src="...."/>

您正在寻找一个类似bbcode的替换系统。网上有很多这样的人。一个例子:http://snipplr.com/view/2296/php--bbcode/

我不是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

PHP是服务端,所以你需要使用客户端技术,比如Javascript。

更新:

但是您可以将内容发送到服务器并让PHP解析和格式化。但这取决于你,我不知道你是用Ajax还是想提交?

您可以使用正则表达式和Javascript识别任何链接,Javascript将侦听textchange。Javascript会扫描文本每次它的变化,然后你可以把所有的链接,电子邮件等链接,而不是文本。这将为您的用户提供一个很好的效果。

我自己没有实现这个,所以一定要测试,因为我不知道textchange将如何与粘贴等动作执行。有其他活动的建议吗?