Monday, July 9, 2012

Replace php



Replace php
Replacing some element in strings we use following functions
 str_replace()
 eregi_replace()
 Preg_replace()
 Following example will be replaced the underscore given in each string.


<?php
$field1="My_Database";
$field2="Your_Database";
$field3="Your_tables";
$str1 = str_replace( '_',' ', $field1);
$str2 = eregi_replace( '_',' ', $field2);
$str3 = preg_replace('/[_]+/', ' ',  $field3);
echo $str1."</br>";
echo $str2."</br>";
echo $str3."</br>";
?>
My Database
Your Database
Your tables

No comments:

Post a Comment