Guest User

regex

a guest
Jan 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 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_field_url, even if the $detected_field_url is found multiple times in $content
  8.       } else {
  9.         $detected_field_url = preg_quote($field_url, '/');
  10.  
  11.         $formatted_url = '<a href="$detected_field_url">"$detected_field_url"</a>';
  12.         $formatted_url = preg_quote($formatted_url, '/');
  13.  
  14.         // this is still not echoing anything, i think i am missing something dumb on my part..
  15.         echo preg_replace($detected_field_url, $formatted_url, $content);
  16.       }
  17. ?>
Add Comment
Please, Sign In to add comment