I need a function that will read the results of a page and replace all ' " ; with a NULL value. I saw this from the php funtion list of php.net:
$match=array("ONE","TWO","THREE");
$replace=array("TWO WORDS","MANY LETTERS","OTHER IDEAS");
$sample="ONE SAMPLE";
echo str_replace($match,$replace,$sample);
Is this correct? I think I need to escape the ' " and the ; but unsure what I need to do.
$match=array("'",""",";");
$replace=array("","","");
$sample="ONE SAMPLE";
echo str_replace($match,$replace,$sample);
Thanks,
Aelaron
php replace function Please help Newbie to PHP
Moderator: General Moderators
Code: Select all
<?php
// ' " ;
$from = array('"',"'",";");
$to = array("","","");
$sample = 'This is ONE; wierd """" SAMPLE';
echo str_replace($from,$to,$sample);
?>If you're trying to get rid of them, you can escape them like this:
Code: Select all
$string=str_replace(""","",$string);
$string=str_replace("''","",$string);- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You don't need to escape single quotes within double quotes, sosdibb wrote:If you're trying to get rid of them, you can escape them like this:
Code: Select all
$string=str_replace(""","",$string); $string=str_replace("''","",$string);
Code: Select all
$string=str_replace("''","",$string);Code: Select all
$string=str_replace("'", '', $string);Code: Select all
$string=str_replace('''', '',$string);Code: Select all
$string=str_replace(""","",$string);Code: Select all
$string=str_replace('"', '', $string);Mac