View Full Version : deleting text with 4 varying characters from a string stored in a variable

08-14-2008, 09:17 PM
I use this code to get the source of line 25 of dragcave.net.

$lines = file('http://dragcave.net/user/Christian271');
$line = $lines[25];
I need to delete all
<td><a href="/viewdragon/HkLG">View</a></td>
from it but the HkLG is going to be different every time.
I tried this

$re = '';
$pattern = '/(<td><a href="/viewdragon/)....(">View</a></td>)/';
$line2 = preg_replace($pattern, $re, $line);
echo($line2); but I get the error 'Warning: preg_replace() [function.preg-replace (http://mytoolbaraccess.net84.net/function.preg-replace)]: Unknown modifier 'v' in /home/a9196005/public_html/test.php on line 16' line 16 is $line2 = preg_replace($pattern, $re, $line); Any ideas?

08-15-2008, 12:09 AM
Does escaping the first v work? Like this:

$pattern = '/(<td><a href="\/viewdragon/)....(">View</a></td>)/';

08-15-2008, 02:11 AM
now it's saying 'Warning: preg_replace() [function.preg-replace (http://mytoolbaraccess.net84.net//function.preg-replace)]: Unknown modifier ')' in /home/a9196005/public_html/test.php on line 16'

08-15-2008, 03:12 AM
Well then escape the other one. While your at it, escape the other ones too.

$pattern = '/(<td><a href="\/viewdragon\/)....(">View<\/a><\/td>)/';

08-15-2008, 04:35 AM
It works! :thumbsup: I don't know why I didn't think of that. So that's two times you've helped (you tried to help me find the URL of a frame with javascript) Thanks so much! :D