www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem with my preg_replace

  1. #1
    Join Date
    May 2006
    Posts
    245

    Problem with my preg_replace

    Hi,
    I am trying to replace an image inside an html file using this:

    The file contains this:

    <img class="uiProfilePhoto headerTinymanPhoto uiProfilePhotoLarge img" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/370282_100003830116243_1299179951_q.jpg" alt="" />

    And I want to replace it with this:

    <img class="uiProfilePhoto headerTinymanPhoto uiProfilePhotoLarge img" src="http://example.com/FC.jpg" alt="" />

    This is what I have tried:

    PHP Code:
    $URLSearchString " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";

    $page_html preg_replace("#headerTinymanPhoto uiProfilePhotoLarge img\" src=\"($URLSearchString)\"#"'http://example.com/FC.jpg'$page_html); 
    But its not working.

    Can anyone see what I have done wrong ?

    Is preg_replace the correct tool to use ?

    Thanks.



    .
    Developers Choice Revealed:
    www.devchoice.info
    Which host has won, and why ?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,387
    Maybe something like this?
    PHP Code:
    $URLSearchString " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
    $page_html preg_replace(
        
    '#(headerTinymanPhoto uiProfilePhotoLarge img" src=")['.$URLSearchString.']*?"#',
        
    '$1http://example.com/FC.jpg"',
        
    $page_html
    ); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles