PHP/String/ereg replace

Материал из Web эксперт
Перейти к: навигация, поиск

back-reference parenthesized substrings

   <source lang="html4strict">

<? $url = "wbex (http://www.wbex.ru)"; $url = ereg_replace("http://(([A�Za�z0�9.\-])*)", "<a href=\"\\0\">\\0</a>",$url); print $url; ?>

 </source>
   
  


ereg_replace

   <source lang="html4strict">

<? $inmystring = "Hello World!"; $mynewstring = ereg_replace("Hello", "Goodbye", $inmystring); print $mynewstring; ?>

 </source>
   
  


ereg_replace-2

   <source lang="html4strict">

<?php $url = "wbex (http://www.wbex.ru)"; $url = ereg_replace("http://([a-zA-Z0-9./-]+)([a-zA-Z/]+)", "<a href=\"\\0\">\\0</a>", $url); print $url; ?>

 </source>
   
  


ereg_replace() function searches for string and replaces pattern if found.

   <source lang="html4strict">

The syntax is: string ereg_replace (string pattern, string replacement, string string) <?

   $copy_date = "Copyright 2009";
   $copy_date = ereg_replace("([0?9]+)", "2010", $copy_date);
   print $copy_date;

?>

 </source>
   
  


ereg_replace.php

   <source lang="html4strict">

<?php

  $text = "http://www.wbex.ru/.";
  echo ereg_replace("http://([a-zA-Z0-9./-]+)$", "<a href=\"\\0\">\\0</a>", $text);

?>

 </source>
   
  


Using ereg_replace

   <source lang="html4strict">

<?php

   $s = "m@t.ca";
   echo ereg_replace ("(alpha:+)@(alpha:+)\.(alpha:{2,4})",
     "\1 at \2 dot \3", $s)

?>

 </source>