error in 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
crishna369
Forum Newbie
Posts: 10
Joined: Mon May 25, 2009 12:35 am

error in replace

Post 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.
Last edited by Benjamin on Tue May 26, 2009 10:35 am, edited 1 time in total.
Reason: Changed code type from text to php.
Scriptor
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 12:27 am

Re: error in replace

Post by Scriptor »

why not use str_replace for the first two?
crishna369
Forum Newbie
Posts: 10
Joined: Mon May 25, 2009 12:35 am

Re: error in replace

Post by crishna369 »

cause i want to replace only first occurrence of "(".
MeLight
Forum Commoner
Posts: 26
Joined: Sun Apr 19, 2009 12:39 pm
Location: Israel

Re: error in replace

Post 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);
crishna369
Forum Newbie
Posts: 10
Joined: Mon May 25, 2009 12:35 am

Re: error in replace

Post by crishna369 »

Code: Select all

$t = preg_replace('/(/', '', $val, 1);
is the 11th line
MeLight
Forum Commoner
Posts: 26
Joined: Sun Apr 19, 2009 12:39 pm
Location: Israel

Re: error in replace

Post by MeLight »

ok then, if change it to what I've showed you it should work
crishna369
Forum Newbie
Posts: 10
Joined: Mon May 25, 2009 12:35 am

Re: error in replace

Post by crishna369 »

thnx buddy its working
Post Reply