Forum Moderators: coopster
I know there is there a quick way to find these types of strings in a block such as:
google’s
using a regular expression that would take any character before and after the string without grabbing the surrounding text but I can't seem to get it.
Can someone point me in the right direction?
any character before and after the string without grabbing the surrounding text
Can you clarify what it is you're trying to match? Perhaps give the data that you would like to obtain from the string you posted.
the str_replace and even ereg_replace isn't catching those character codes (or any number strings for that matter) unless they are standing alone in the block such as "this is the code for an apostrophe ’ it will show as a single character in your browser"
So I need to match &#--; without regard to what characters are before or after it in a string.
$string="google’s";
// match &# followed by one or more numbers, then a semi-colon
$pattern="/(&#[0-9]+;)/";
// replace with a space
$string=preg_replace($pattern,' ',$string);
// show output
echo $string;
If the characters are not always numbers, you can match one or more characters that aren't a semi-colon:
$pattern="/(&#[^;]+;)/";
[edited by: Receptional_Andy at 8:37 pm (utc) on June 8, 2008]
Is there a quick reference to this stuff somewhere?
The PHP manual pages are often your best starting point for resources. The modifiers and syntax [php.net] descriptions can take some time to learn, but well worth your effort!