how i can pass a variable containing an integer value to preg_replace.
plz help.
how i can pass an intege variable to preg_replace
Moderator: General Moderators
-
crishna369
- Forum Newbie
- Posts: 10
- Joined: Mon May 25, 2009 12:35 am
Re: how i can pass an intege variable to preg_replace
Code: Select all
$subj = "hello, here are some nums 12384";
$int = 3;
$patt = "/$int/";
echo preg_replace($patt, "<blah>", $subj);
Last edited by Benjamin on Wed May 27, 2009 10:00 am, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.
-
crishna369
- Forum Newbie
- Posts: 10
- Joined: Mon May 25, 2009 12:35 am
Re: how i can pass an intege variable to preg_replace
thanx its working!!!!!!!!
-
crishna369
- Forum Newbie
- Posts: 10
- Joined: Mon May 25, 2009 12:35 am
Re: how i can pass an intege variable to preg_replace
sorry buddy its not working
its removing the number 3 but not replacing it with the text.
its removing the number 3 but not replacing it with the text.
Re: how i can pass an intege variable to preg_replace
You may also want to read:Forum Rules wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Re: how i can pass an intege variable to preg_replace
It work on my machine. Do you have any other preg_replace commands afterwards? If you're removing tags, the "<blah>" will be removed also. try this:
If it still doesn't work, post your code.
Code: Select all
$subj = "hello, here are some nums 12384";
$int = 3;
$patt = "/$int/";
echo preg_replace($patt, "three", $subj); //"<blah>" replaced with "three"