Advertisement
Guest User

preg_replace

a guest
Jan 27th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.       // if the $field_url is not present, proceed as normal
  3.       if (empty($field_url)) {
  4.         echo $content;
  5.       // if the $field_url is present, format it as an actual url
  6.       // the problem here is that $content may contain multiple urls, I want to do a regex
  7.       // on only the $detected_url, even if the $detected_url is found multiple times in $content
  8.       } else {
  9.         $detected_field_url = $field_url;
  10.         $formatted_url = "<a href=\"$detected_field_url\">$detected_field_url</a>";
  11.         // this actually echoes nothing, i think because of unescaped characters?
  12.         echo preg_replace("/$detected_field_url/", "/$formatted_url/", $content);
  13.       }
  14. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement