Page 1 of 1

error in replace

Posted: Mon May 25, 2009 2:52 am
by crishna369
below is my code:

Code: Select all

 
$val = "(PT) :- PTFE with 316L SST(Diaphragm) 316L SST(Others)";
$t = preg_replace('/(/', '', $val, 1);
$tp = preg_replace('/)/', '', $t, 1);
$temp = str_replace($ans['Code'],"",$tp);
$temp1 = str_replace(":-","",$temp);
echo $temp1;
 
And I m getting this error:
Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 1 in C:\xampp\htdocs\crm\replace.php on line 11

plz help me.

Re: error in replace

Posted: Mon May 25, 2009 3:07 am
by Scriptor
why not use str_replace for the first two?

Re: error in replace

Posted: Mon May 25, 2009 3:38 am
by crishna369
cause i want to replace only first occurrence of "(".

Re: error in replace

Posted: Mon May 25, 2009 3:39 am
by MeLight
crishna369 wrote: And I m getting this error:
Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 1 in C:\xampp\htdocs\crm\replace.php on line 11
Letting us know which line is '11' would be nice. In any case, my guess is that you're not escaping the parenthesis like you should
you're doing this:

Code: Select all

$t = preg_replace('/(/', '', $val, 1);
while you should be doing this:

Code: Select all

$t = preg_replace('/\(/', '', $val, 1);

Re: error in replace

Posted: Mon May 25, 2009 3:43 am
by crishna369

Code: Select all

$t = preg_replace('/(/', '', $val, 1);
is the 11th line

Re: error in replace

Posted: Mon May 25, 2009 3:45 am
by MeLight
ok then, if change it to what I've showed you it should work

Re: error in replace

Posted: Wed May 27, 2009 5:15 am
by crishna369
thnx buddy its working