RE: [PHP] Replace or regex?
| From: | Graham Cossey | Date: | Thu, 30 Sep 2004 10:04:23 +0000 |
| Subject: | RE: [PHP] Replace or regex? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198244@lists.php.net to get a copy of this message | ||
If you can change the ##text## to say /#text#/ it would be easier as you
could then do something like:
$id = substr($orig_text,strpos($orig_text, '/#')+2,strpos($orig_text,
'#/')-1);
$new_text = str_replace( '/#',
'href="somewhere.php?id='.$id.'">',
$orig_text);
$new_text = str_replace( '#/', '</a>', $new_text);
see:
http://www.php.net/manual/en/ref.strings.php
HTH
Graham
-----Original Message-----
From: Gareth Williams [mailto:gareth@venditor.com]
Sent: 30 September 2004 09:38
To: mario
Cc: php-general@lists.php.net
Subject: Re: [PHP] Replace or regex?
Well, if you can do it without a regex, then it's always best, because
the regex engine slows things down.
On 30 Sep 2004, at 10:39, mario wrote:
> Hi all
>
> I have a string: ##CODE## and I want to replace that with <a
> href="somewhere.php?id=CODE">CODE</a>
>
> can u help?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php