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. Quote Link to comment 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> Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted June 10, 2008 Author Share Posted June 10, 2008 Fixed. Thanks anyways. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.