Page 1 of 1

Replacing some text with varying number with a link

Posted: Fri Feb 12, 2010 11:37 am
by runder
I need to change a text in a PHP page from this:

Code: Select all

 Ticket #23 
to this:

Code: Select all

 <a href="http://www.somelink.com/ticket/23">Ticket #23</a> 
where the actual number (in this case, 23) is a varying number. Meaning, if the ticket was #87 (Ticket #87), the actual output would have been

Code: Select all

 <a href="http://www.somelink.com/ticket/87">Ticket #87</a> 
I know I need to work with preg_replace, but it's been hours I still can't figure it out :') It's mainly storing the number in a variable to be reused with some sort of variable string ($1, $2) that poses a lot of problem to me when I'm trying to figure this out.

Any help is appreciated. Thanks :)

Re: Replacing some text with varying number with a link

Posted: Fri Feb 12, 2010 12:13 pm
by josh
From my site http://www.vehiclefits.com/changelog.php

Code: Select all

 
$ob = preg_replace( '#([0-9]+):#', '<a target="_blank" href="http://tracker.ne8.net/view.php?id=$1">$1</a>:', $ob );
Consider it public domain now ;-)

Re: Replacing some text with varying number with a link

Posted: Fri Feb 12, 2010 12:23 pm
by runder
Oh wow, I love you :) the programmer way of course ^_^;

Thank you very much, Josh.