Goldeneye Posted June 7, 2008 Share Posted June 7, 2008 Basically: I'm trying to create a regular expression where you input: int://board=1&topic=2 and it outputs Topic 2 Problem: Nothing is being parsed past the ampersand (&); it'll output Board 1&topic=2 The expression: <?php $str = 'int://board=1&topic=2' preg_replace( '|int://board=([\d]+)&topic=([\d]+)|i', '<a href="http://foo.bar/forums/topic.php?board=$1&topic=$2" target="_blank">Topic $2</a>', $str ); ?> I was thinking it's because I'm missing a modifier, but I'm not sure which one (if any) to use. A preemptive thanks. Link to comment https://forums.phpfreaks.com/topic/109076-solved-this-regular-expression-does-not-parse-anything-past-an-ampersand-amp/ Share on other sites More sharing options...
effigy Posted June 9, 2008 Share Posted June 9, 2008 It works once you add the missing semicolon for $str's defintion and echo out the data, of course. <pre> <?php $str = 'int://board=1&topic=2'; echo preg_replace( '|int://board=([\d]+)&topic=([\d]+)|i', '<a href="http://foo.bar/forums/topic.php?board=$1&topic=$2" target="_blank">Topic $2</a>', $str ); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/109076-solved-this-regular-expression-does-not-parse-anything-past-an-ampersand-amp/#findComment-561117 Share on other sites More sharing options...
Goldeneye Posted June 9, 2008 Author Share Posted June 9, 2008 Well that's not quite what I'm looking for. That's just a mock-up code to keep things simple though. Here's how I have set up in my script <?php $text = 'int://board=1&topic=2'; function processText($str){ $str = preg_replace( '|int://board=([\d]+)&topic=([\d]+)|i', '<a href="http://foo.bar/forums/topic.php?board=$1&topic=$2" target="_blank">Topic $2</a>', $str) ); return $str; } echo processText($text); ?> Link to comment https://forums.phpfreaks.com/topic/109076-solved-this-regular-expression-does-not-parse-anything-past-an-ampersand-amp/#findComment-561581 Share on other sites More sharing options...
Goldeneye Posted June 10, 2008 Author Share Posted June 10, 2008 Fixed. Thanks anyways. Link to comment https://forums.phpfreaks.com/topic/109076-solved-this-regular-expression-does-not-parse-anything-past-an-ampersand-amp/#findComment-561658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.