On 17/11/06, Paul Novitski <[EMAIL PROTECTED]> wrote:
At 11/16/2006 08:46 PM, Myron Turner wrote:
>The underscore plus alphanumeric are included in \w, so to get a
>regex such as you want:
> [\w\s\.\-&\']+
>You should escape the dot because the unescaped dot stands for any
>single character, which is why .* stands for any and all characters.
Not actually. Inside a character class, a dot is just a period. You
may escape it (or any other character) but you don't need to. To
quote the manual:
______________________
Meta-characters
...
In a character class the only meta-characters are:
\
general escape character
^
negate the class, but only if the first character
-
indicates character range
]
terminates the character class
...
Square brackets
...
A closing square bracket on its own is not special. If a closing
square bracket is required as a member of the class, it should be the
first data character in the class (after an initial circumflex, if
present) or escaped with a backslash.
...
All non-alphanumeric characters other than \, -, ^ (at the start) and
the terminating ] are non-special in character classes, but it does
no harm if they are escaped.
______________________
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
In any case, none of those solutions work. Try code:
<?php
$makeLinkPlaceHolder=0;
function findLinks ($matches) {
global $linkTextArrayPlaceHolder;
++$linkTextArrayPlaceHolder;
// Make two peices and fill them with what they should be
$matches[0]=str_replace("[", "", $matches[0] );
$matches[0]=str_replace("]", "", $matches[0] );
$parts=explode("|", $matches[0]);
print "<br /><br />$parts[0] | $parts[1]";
$returnString="[".$linkTextArrayPlaceHolder."]";
return $returnString;
}
$text="This is some text.
This tag has no spaces and no pipes [TestTag]
This tag has no spaces and a pipe [TestTag|AfterPipe]
This tag has a space and no pipes [Test Tag]
This tag has a space and a pipe [Test Tag|AfterPipe]";
// Clean up the text
$text=str_replace("\r\n", "\n", $text);
$text=str_replace("\r", "\n", $text);
$text=str_replace("\n", "<br />", $text);
print $text;
// THIS IS THE PROBLEMATIC CODE
$text=preg_replace_callback('/\[([A-Za-z0-9\¦\'.-]+)\]/i' ,
"findLinks", $text);
print "<br /><br />".$text;
?>
Dotan Cohen
http://lyricslist.com/
http://what-is-what.com/