NYCPHP Meetup

NYPHP.org

[nycphp-talk] regexp: feeling stupid

Marc Antony Vose suzerain at suzerain.com
Wed Mar 17 14:15:48 EST 2004


hey there:

i am having one of those 'feeling stupid' moments, but i have a 
search and replace that is for some reason working on my home machine 
and failing on my remote server.

i need to match everything inside a <sup> html tag, even if that 
includes other html tags, and replace it with something else.  here's 
my call:

---
$fn_text_to_match = '|<sup class="gt_article_footnote">([^</sup>]+)</sup>|';
$art_body_real = preg_replace_callback( 
$fn_text_to_match,'handleFootnote',$art_body );

the function handleFootnote, does this:

$all_footnotes = array();
function handleFootnote( $matches ){
	global $fn_ctr, $all_footnotes, $art_id;

	//echo "we found a match: " . $fn_ctr . " | " . $matches[1] . "<br />";
	$all_footnotes[$fn_ctr] = array(
		"text" => $matches[1]
	);

	$fn_ctr++;

	return '<sup class="gt_article_footnote"><a 
href="javascript:showGTFootnotes(' . "'" . $fn_ctr . "'" . ')">' . 
($fn_ctr+1) . '</a></sup>';
}
---

Basically, what's going on here, is the client has a tool where they 
can enter text in superscript, then i need to parse that text out and 
replace it with a number, and extract the text they had as a 
'footnote' which is exported to a text file.

But the problem with my original match is i need to match the <sup 
class="gt_article_footnote">...</sup>

can anyone help me with that first line of code there?  i am not the 
most experienced with regular expressions...

cheers,

-- 
Marc Antony Vose
http://www.suzerain.com/

The thing I love most about deadlines is the wonderful WHOOSHing 
sound they make as they go past.
-- Douglas Adams.



More information about the talk mailing list