Thread: Preg_match help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Preg_match help


    Hi,
    I dont know if this should be posted here or on the php page but Basically I am trying to use the code below:
    Code:
    <?php $eurovalue = file_get_contents("dump.txt"); $eurovalue = htmlspecialchars($eurovalue); $pattern = '/<td><a.*>USD\/EUR<\/a><\/td>.*<td\s*\w*>\s*<img\s*[\w\d]*\s*\/>(\d+)<\/td>/si'; preg_match($pattern,$eurovalue,$euroarray); $euroresult = $euroarray[0]; echo $euroresult; ?>
    To find this code:
    Code:
    <td><a href="/business/currencies/quote?srcAmt=1&amp;srcCurr=USD&amp;destAmt=&amp;destCurr=EUR">USD/EUR</a></td> <td class="data changeUp"> <img width="9" height="10" src="/resources_v2/images/changeUp.gif" />0.69070</td>
    In a script that contains similar <td>'s, also the 0.69070 is subject to change. The preg_match that I am using isnt working and I cant work out why. I imagine it is something to do with the regex. The code that it is searching for is located in dump.text and this is all working fine, it just seems to be the preg_match.
    Any help would be appreciated,
    Thanks
    Rhys
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,053
    Rep Power
    9398
    I haven't looked at the regex, but try without using htmlspecialchars().
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0
    Hi (I had to change my account as my previous one didnt work)
    I tried removing the htmlspecialchars but it still didnt work. I think it is needed as the Regex searches for the html to identify the value, so without the htmlspecialchars it cant do this.
    Any other ideas?
    Thanks
    Rhys

IMN logo majestic logo threadwatch logo seochat tools logo