Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting image url to complete html image tag
    primarykey
    data
    text
    <p>I am working on comments thing and i want my user to be able to post image url which i will change into image url with tag</p> <p>my function </p> <pre><code>function ImageTag($text) { // The Regular Expression filter $reg_exUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // The Text you want to filter for urls if(preg_match_all($reg_exUrl, $text, $url)) { // make the urls hyper links $matches = array_unique($url[0]); foreach($matches as $match) { $check = substr($match, -4); if ($check == ".jpg" || $check == ".png" || $check == ".gif" || $check == "jpeg" || $check == ".JPG" || $check == ".PNG" || $check == ".GIF" || $check == "JPEG"){ $replacement = "&lt;br/&gt;&lt;img src=$match&gt;"; $text = str_replace($match, $replacement, $text); } } return nl2br($text); } else { // if no urls in the text just return the text return nl2br($text); } } $text = "The text you want to filter goes here. &lt;img src='http://static.php.net/www.php.net/images/php.gif'&gt; http://www.facebook.com http://static.php.net/www.php.net/images/php.gif"; $content = ImageTag($text); echo $content; </code></pre> <p>I am half done with my function but i am not sure how to solve image which are already have html tags</p> <p><strong>This is what i am getting</strong></p> <p><img src="https://i.stack.imgur.com/vHKUm.jpg" alt="enter image description here"></p> <p>source code:</p> <pre><code>The text you want to filter goes here. &lt;img src="&amp;lt;br/&amp;gt;&amp;lt;img src=http://static.php.net/www.php.net/images/php.gif&amp;gt;"&gt; http://www.facebook.com &lt;br&gt;&lt;img src="http://static.php.net/www.php.net/images/php.gif"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload