Hi,
I cannot seem to wrap my brain around preg_replace. Though I've read
the help file backwords and forwards. :/ Hoping someone can give me
a solution here.
Problem: Given string 'str' which may contain new lines and will
contain html code, IN this string any "words" that begin with an
underscore I want to replace with a given word. A word here being a
group of chars preceded by a space or null (start of line) and closed
by a space or null or htmltag start<. (Hope that makes sense.)
My current solution/hack:
$str=str_replace( array('_m<br />','_mt<br />','_t<br />'), ' ',
$str);
This is *a* solution, IN THAT I am manually entering into a db the
values _m _mt _t and then, this str_replace will take them and
replace them with a space. Ok, good so far. But I would LIKE to
be able to add new values to the db (ie _x _y _z _example _s7 )
and have THOSE be replaced by a " ".
However this is not the *best solution, obviously. I'm sure it can be
done with preg_replace. I hope!
Other things to note... in the string there are other <br /> tags
which are NOT preceded by a target word.
target words begin with a _ BUT if that is a bad character to choose
it can be anything you want, within reason. *g* In otherwords
starting them with a < would be bad (probably, given my limited info),
and starting target words with an alpha character would be bad because
there are other 'words' which are NOT targetted that begin with alpha.
So... could anyone help me here? If you feel like adding an
explanation as to why your preg_replace works, that would be groovy :)
But beggars cannot be choosers and I would be ecstatic with just the
preg_replace itself!!
Hopefully I haven't left anything out of the string's properties.
Thanks a bazillion,
Sherry
Sherry
--
me(www.CactusBlossom.org) fyi(http://allmyfaqs.com/faq.pl?How_to_post)
Before you criticize someone you should walk a mile in their shoes. That
way when they get angry, you're a mile away and have their shoes.