Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts

    deleting text with 4 varying characters from a string stored in a variable

    I use this code to get the source of line 25 of dragcave.net.
    PHP Code:
    $lines file('http://dragcave.net/user/Christian271');
    $line $lines[25]; 
    I need to delete all
    Code:
    <td><a href="/viewdragon/HkLG">View</a></td>
    from it but the HkLG is going to be different every time.
    I tried this
    PHP Code:
    $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]: Unknown modifier 'v' in /home/a9196005/public_html/test.php on line 16' line 16 is $line2 = preg_replace($pattern, $re, $line); Any ideas?

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Does escaping the first v work? Like this:
    Code:
    $pattern = '/(<td><a href="\/viewdragon/)....(">View</a></td>)/';

  • #3
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    now it's saying 'Warning: preg_replace() [function.preg-replace]: Unknown modifier ')' in /home/a9196005/public_html/test.php on line 16'

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Well then escape the other one. While your at it, escape the other ones too.
    Code:
    $pattern = '/(<td><a href="\/viewdragon\/)....(">View<\/a><\/td>)/';

  • #5
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It works! 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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •