[PHP] multiple replaces...
Hello there, I have about 30 markers in the text which need to be replaced with the value of a variable or an array. Common sense comes up with eregi_replace(!one!,blah,eregi_replace(!heh!,'foobar',eregi_replace(blah,ho-ho-ho,text))); The list above could go on and on... I'm sure there are better ways to replace many markers or spans of text with something else. A loop? Something even more easier and better? Thanks, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * On 12-01-02 at 12:49 * Lauri Vain said Hello there, I have about 30 markers in the text which need to be replaced with the value of a variable or an array. Common sense comes up with eregi_replace(!one!,blah,eregi_replace(!heh!,'foobar',eregi_replace(blah,ho-ho-ho,text))); The list above could go on and on... I'm sure there are better ways to replace many markers or spans of text with something else. A loop? Something even more easier and better? Thanks, Lauri If the 'markers' are in some kind of sequence (like marker1, marker2 etc) you could use a loop. - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8QCOJHpvrrTa6L5oRAu8zAJ0ae4AFomhUhUaK8MneNdm/BtnTNACfXhGh 9FydYCt1iS/rmBh83LyBWHs= =CQIT -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] multiple replaces...
Hi Nick, Yes, I thought about that. But, what should I do when the markers are absolutely NOT in any sequence. I also thought about something like $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[1][1] = test;//marker $replace[1][2] = foobar; //replace with $replace[1][1] = repl;//marker $replace[1][2] = humpty-dumpty; //replace with $replace[1][1] = blah;//marker $replace[1][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? Yours, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -Original Message- From: Nick Wilson [mailto:[EMAIL PROTECTED]] Sent: 12. jaanuar 2002. a. 13:53 To: [EMAIL PROTECTED] Subject: Re: [PHP] multiple replaces... If the 'markers' are in some kind of sequence (like marker1, marker2 etc) you could use a loop. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Whoops (was:RE: [PHP] multiple replaces...)
Whoops, forgot to change the first number in every one of those. The first numbers in the brackets should increase after every two lines... The correct one: $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[2][1] = test;//marker $replace[2][2] = foobar; //replace with $replace[3][1] = repl;//marker $replace[3][2] = humpty-dumpty; //replace with $replace[4][1] = blah;//marker $replace[4][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? Yours, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * On 12-01-02 at 13:02 * Lauri Vain said Hi Nick, Yes, I thought about that. But, what should I do when the markers are absolutely NOT in any sequence. I also thought about something like $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[1][1] = test;//marker $replace[1][2] = foobar; //replace with $replace[1][1] = repl;//marker $replace[1][2] = humpty-dumpty; //replace with $replace[1][1] = blah;//marker $replace[1][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? I don't think speed will be an issue unless you have thousands of markers, in which case you'll need to re-think the whole thing. Can you not put all of your markers in an array like $markers=array(m1, m2, m_whatever); and all your replacements likewise $replace=array(r1, r2, r_whatever); and then loop through like that? If not, explain a little more about the context of the problem and let's see if we can come up with an alternative. - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8QCk+HpvrrTa6L5oRAozIAJ4opVPFNwawBmQNIAHLZN/gdCt+lgCeLgmC 5hurUMezrXCg3cVtYgieGGE= =xRPE -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
Yes, I thought about that. But, what should I do when the markers are absolutely NOT in any sequence. =sequence would matter if it was possible that one of the markers could replace some text and that replacement subsequently became the marker for a further replacement ... nightmare=recursion! I also thought about something like $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[1][1] = test; //marker $replace[1][2] = foobar; //replace with $replace[1][1] = repl; //marker $replace[1][2] = humpty-dumpty; //replace with $replace[1][1] = blah; //marker $replace[1][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? =check out string functions. On simple stuff they will beat RegEx for speed hands down - but watch out if case-sensitivity is relevant. =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
No need to loop. str_replace() already supports arrays! check the manual. bvr. On Sat, 12 Jan 2002 12:57:10 -, DL Neil wrote: Yes, I thought about that. But, what should I do when the markers are absolutely NOT in any sequence. =sequence would matter if it was possible that one of the markers could replace some text and that replacement subsequently became the marker for a further replacement ... nightmare=recursion! I also thought about something like $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[1][1] = test; //marker $replace[1][2] = foobar; //replace with $replace[1][1] = repl; //marker $replace[1][2] = humpty-dumpty; //replace with $replace[1][1] = blah; //marker $replace[1][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? =check out string functions. On simple stuff they will beat RegEx for speed hands down - but watch out if case-sensitivity is relevant. =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces... (2)
And so does preg_replace() if you need any regular expressions. Though str_replace() is probably faster when this is not the case. http://www.php.net/manual/en/function.str-replace.php http://www.php.net/manual/en/function.preg-replace.php bvr. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
If you only want to replace strings, then drop the regular expression functions! (a common mistake) Use for example str_replace, or in this case, strtr which is better because it accepts an array as replacement pattern. For example: $foo = array(foo = apple, bar = banana); $string = I like foos and bars; $string = strtr($string, $foo); echo $string; output: I like apples and bananas // Victor - Original Message - From: 'Nick Wilson' [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 1:17 PM Subject: Re: [PHP] multiple replaces... -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * On 12-01-02 at 13:02 * Lauri Vain said Hi Nick, Yes, I thought about that. But, what should I do when the markers are absolutely NOT in any sequence. I also thought about something like $replace[1][1] = !one!; //marker $replace[1][2] = hehee; //replace with $replace[1][1] = test; //marker $replace[1][2] = foobar; //replace with $replace[1][1] = repl; //marker $replace[1][2] = humpty-dumpty; //replace with $replace[1][1] = blah; //marker $replace[1][2] = boo; //replace with Now, when I would do a loop thingie that goes through all those, then it would be a pretty nice and compact solution... What about speed issues regarding this solution? I don't think speed will be an issue unless you have thousands of markers, in which case you'll need to re-think the whole thing. Can you not put all of your markers in an array like $markers=array(m1, m2, m_whatever); and all your replacements likewise $replace=array(r1, r2, r_whatever); and then loop through like that? If not, explain a little more about the context of the problem and let's see if we can come up with an alternative. - -- Nick Wilson Tel: +45 3325 0688 Fax: +45 3325 0677 Web: www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8QCk+HpvrrTa6L5oRAozIAJ4opVPFNwawBmQNIAHLZN/gdCt+lgCeLgmC 5hurUMezrXCg3cVtYgieGGE= =xRPE -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
have a look at eval() Paul Roberts [EMAIL PROTECTED] From: Lauri Vain [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 11:44 AM Subject: [PHP] multiple replaces... Hello there, I have about 30 markers in the text which need to be replaced with the value of a variable or an array. Common sense comes up with eregi_replace(!one!,blah,eregi_replace(!heh!,'foobar',eregi_replace(b lah,ho-ho-ho,text))); The list above could go on and on... I'm sure there are better ways to replace many markers or spans of text with something else. A loop? Something even more easier and better? Thanks, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
try str_replace() ... it allows you to pass an array into the replace function. /dkm - Original Message - From: Paul Roberts [EMAIL PROTECTED] To: Lauri Vain [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 4:35 PM Subject: Re: [PHP] multiple replaces... have a look at eval() Paul Roberts [EMAIL PROTECTED] From: Lauri Vain [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 11:44 AM Subject: [PHP] multiple replaces... Hello there, I have about 30 markers in the text which need to be replaced with the value of a variable or an array. Common sense comes up with eregi_replace(!one!,blah,eregi_replace(!heh!,'foobar',eregi_replace(b lah,ho-ho-ho,text))); The list above could go on and on... I'm sure there are better ways to replace many markers or spans of text with something else. A loop? Something even more easier and better? Thanks, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] multiple replaces...
- Original Message - From: Dennis Moore [EMAIL PROTECTED] To: Paul Roberts [EMAIL PROTECTED]; Lauri Vain [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: 12. siječanj 2002 23:33 Subject: Re: [PHP] multiple replaces... try str_replace() ... it allows you to pass an array into the replace function. /dkm - Original Message - From: Paul Roberts [EMAIL PROTECTED] To: Lauri Vain [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 4:35 PM Subject: Re: [PHP] multiple replaces... have a look at eval() Paul Roberts [EMAIL PROTECTED] From: Lauri Vain [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, January 12, 2002 11:44 AM Subject: [PHP] multiple replaces... Hello there, I have about 30 markers in the text which need to be replaced with the value of a variable or an array. Common sense comes up with eregi_replace(!one!,blah,eregi_replace(!heh!,'foobar',eregi_replace(b lah,ho-ho-ho,text))); The list above could go on and on... I'm sure there are better ways to replace many markers or spans of text with something else. A loop? Something even more easier and better? Thanks, Lauri -- Tharapita Creations [dynamic web applications] [EMAIL PROTECTED] Mobile: +372 53 410 610 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]