Re: PHP function inside a regex - possible?
| From: | kev | Date: | Thu, 01 Jun 2000 18:54:49 +0000 |
| Subject: | Re: PHP function inside a regex - possible? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-857@lists.php.net to get a copy of this message | ||
>
> > How do I guard against that, but ensure that it still modifies every bolded
> > term?
>
> Hi,
>
> This is just a preg issue. You need to make your .* stingy:
>
> $newtext = preg_replace("/<B>(.*?)<\/B>/e", "\"<A
> href=\" . '\\1' .
> \"><B>\" . '\\1' . \"</B></A>\"",
> $text );
The only change here was moving the ? to inside the brackets, right?
Here's the actual code I'm working with now (only difference is the urlencode()
function, but that shouldn't nake any difference should it?):
$text = "Turn <B>term 1</B> and <B>term 2</B> to a link";
$newtext = preg_replace( "/<B>(.*?)<\/B>/e",
"\"<A
href=/search.php?query=\".urlencode('\\1').\"><B>\".'\\1'.\"</B></A>\"",
$text );
echo "\$text = $text<BR>";
echo "\$newtext = $newtext<BR>";
But I now just get a parser error:
Parse error: parse error in /usr/local/apache/htdocs/megsoc2/test/boldlinks1.php
on line 0
and instead of a modified 'term 2' I just get a space.
Any ideas?
thanks again,
- Kev