I have been trying to figure out how to use the preg_replace() function...
Problem is I dont want to replace the ' in my file I am importing. I just want to remove them.
What function will remove the ' in stead of replacing it
I have been trying to figure out how to use the preg_replace() function...
Problem is I dont want to replace the ' in my file I am importing. I just want to remove them.
What function will remove the ' in stead of replacing it
$text = str_replace("'", '', $text);
replace it with nothing.
preg_replace($pattern, '', $string);
laserlight wrote:
$text = str_replace("'", '', $text);
that work same way with an array?
that work same way with an array?
Yes. Read the PHP Manual on [man]str_replace/man
Dont use preg_match() here as you dont need the power of regular expressions, so it becomes unnecessary overhead instead.
laserlight wrote:Yes. Read the PHP Manual on [man]str_replace/man
Dont use preg_match() here as you dont need the power of regular expressions, so it becomes unnecessary overhead instead.
Just added the following code to my file write loop... worked like a charm
$data= str_replace("'", '', $data);
didnt try preg+match() but I know that preg_replace() doesnt work
thanks for your help
preg_match wouldn't work, because it doesn't change anything.
cbrknight wrote:but I know that preg_replace() doesnt work
Er, yes it does.
$data = preg_replace("/'/", '', $data);
But as already noted, is entirely overkill in this case.
didnt try preg+match() but I know that preg_replace() doesnt work
Sorry, I meant preg_replace(), as per etully's code example.
Weedpacket wrote:preg_match wouldn't work, because it doesn't change anything.
Er, yes it does.
$data = preg_replace("/'/", '', $data);
But as already noted, is entirely overkill in this case.
I see what I did wrong. I didnt use a slash for the double quote.. only for the apostrope.