Page 1 of 1

find and replace

Posted: Mon Feb 06, 2012 2:37 pm
by digrev01
hi,could you plase say what is wrong .when i click submit button nothing happens

Code: Select all


<?php 
$offset=0;
if(isset($_POST['text']) && isset($_POST['search']) && isset($_POST['replace']) )
{
$text=$_POST['text'];
$src=$_POST['search'];
$rplc=$_POST['replace'];
$search_len=strlen($src);
if(!empty($text) && !empty($src) && !empty($rplc) )
{
       while($strpos=strpos($text,$src,$offset))
{
echo $offset=$strpos+$str_len.'<br>';
}
}
else
{
echo "fill all the  fields";
}

}

?>
		



<form action="index.php" method="post">
<textarea name="text" cols="30" rows="6"></textarea><br><br>



Search For :   <input name="search" type="text"><br>
ReplaceWith :  <input name="replace" type="text"><br><br>


<input name="submit" type="submit" value="FindAndReplace"><br>

</form>



Re: find and replace

Posted: Mon Feb 06, 2012 2:55 pm
by Celauran

Code: Select all

echo str_replace($src, $rplc, $text);

Re: find and replace

Posted: Mon Feb 06, 2012 3:07 pm
by digrev01
hi i am really wondering one thing sometimes code dosent run if php block under html block and sometimes code must be above the all the html stuff like this code i changed the html and php block upside down and it works any idea or any logical reason for this?

Re: find and replace

Posted: Mon Feb 06, 2012 3:37 pm
by digrev01
now this:((

Notice: A non well formed numeric value encountered in C:\wamp\www\findAndRepllace\index.php on line 13