str_replace problem

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

str_replace problem

Post by itsmani1 »

i am trying to replace "<?" but its not working here is code:

Code: Select all

$desc="<?";
$filter=array("<?php","\<?","\?>","javascript","script");
$filtered_desc = str_replace($filter, "", $desc);
echo $filtered_desc;
any way?

thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

test data
expected results
actual result
?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

this works

Post by yacahuma »

this works for me

Code: Select all

$str = "<?php javascript echo \"hello\";?>";
$data = str_replace(array('<?php','javascript','<?','?>'),'', $str);
echo $data;
Post Reply