[thelist] Regexp help?
Dougal Campbell
dougal at gunters.org
Fri Sep 19 13:47:34 CDT 2003
On Fri, 19 Sep 2003, Simon Willison wrote:
> Dougal Campbell wrote:
> > I've been searching for a regexp that will let me do text replacements
> > inside HTML text, but not within HTML tags themselves. In other words,
> > if I had content like this:
> >
> > <a href="/meta/RSS.xml" title="My RSS feed">Our RSS 2.0 feed</a>
> >
> > I want to be able to modify the text 'RSS' without breaking the link or
> > the title attribute.
>
> Aaaaar matey. That's one dirty dawg of a problem, but I vanquished it
> last night convertin' my blog to pirate. Here's the trick, ya scurvy
> land lubber:
>
> function myFunction($bits) {
> $text = $bits[1];
> // Now run the replacements on $text
> // ...
> return '>'.$text.'<';
> }
>
> $text = preg_replace_callback('/>(.*?)</s', 'myFunction', $text);
>
> That thar snippet be just the trick. Now down yer grog, fire up yer
> hornpipe and find yerself a comely wench. Ye international talk like a
> pirate is almost at an end!
Yaarrr! And that be just th' thin' I be needin' it for, matey! Blow me
down!
Currently, the pirate filter I wrote for my blog is doing subs inside
tags, and I wanted to fix that before I release the code. My thanks t'
ye, old salt! I was tryin' to make th' problem more complicated that it
had t' be. Yer solution should do th' trick just fine, and a bottle of
rum!
--
Ernest MacDougal Campbell III, MCP+I, MCSE <dougal at gunters.org>
http://dougal.gunters.org/ http://spam.gunters.org/
Web Design & Development: http://www.mentalcollective.com/
This message is guaranteed to be 100% eror frea!
More information about the thelist
mailing list