find and replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
digrev01
Forum Newbie
Posts: 22
Joined: Fri Oct 07, 2011 9:15 am

find and replace

Post 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>


User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: find and replace

Post by Celauran »

Code: Select all

echo str_replace($src, $rplc, $text);
digrev01
Forum Newbie
Posts: 22
Joined: Fri Oct 07, 2011 9:15 am

Re: find and replace

Post 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?
digrev01
Forum Newbie
Posts: 22
Joined: Fri Oct 07, 2011 9:15 am

Re: find and replace

Post by digrev01 »

now this:((

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