Str_replace problem

Discussion in 'PHP' started by korfezli1966, Sep 20, 2013.

  1. #1
    //Seller details
    preg_match('#<div data-role="collapsible" data-theme="b" data-content-theme="c">(.*?)</div>#si', $tekrarla, $seller_match);
    $seller = strip_tags(str_replace(Array('src="/', '<img src="http://remotedomain.com/images/icon_telephone.gif" />'), Array('src="http://mydomain.com/images/myimage.gif',''), $seller_match[1]), "<img><h2><br/><b><br>");
    preg_match('#src="(.*?)q=90&w=200&h=100"#si', $seller, $seller_match2);
    $seller = str_replace(Array($seller_match2[1]."q=90&w=200&h=100", '<img'), Array("/img/".image_save(substr($seller_match2[1],0,-1),rand(0,9999)), '<img width="200" height="100" '), $seller);
    PHP:
    As you can see, I pull some of the content from my other website to another and I change icon_telephone.gif with myimage.gif , until here everything is ok.

    But someof my content has a second image on remotedomain, and I also want the code above to check icon_telephone2.gif too, and it replaces it also with myimage2.gif. How can I also add a few code here to let it to check other image adn replace it with the second one?

    Summary:
    remotefirstimage.gif > replace > localfirtimage.gif
    I also want it to check it and be sure to happen this action:
    remotefirstimage.gif > replace > localfirtimage.gif
    remotefirstimage2.gif > replace > localfirtimage2.gif

    Thanks!
     
    korfezli1966, Sep 20, 2013 IP
  2. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #2
    Can't you do something like this:
    $old_images = array('icon_telephone.gif',  'icon_telephone2.gif',  'remotefirstimage.gif',  'remotefirstimage2.gif');
    $new_images = array('my_telephone.gif',  'my_telephone2.gif',  'localimage.gif',  'localimage2.gif');
    $required_html = str_replace($old_images, $new_images, $old_html);
    PHP:
    Instead of doing all that nasty preg replaces, you could just lumm the old images in one array and the respective replacement images on another. Then call str_replaces with those values.
     
    samyak, Sep 21, 2013 IP
    bartolay13 likes this.
  3. realturk

    realturk Active Member

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    I think you should try "preg_replace" http://www.php.net/manual/en/function.preg-replace.php
     
    realturk, Oct 9, 2013 IP
    korfezli1966 likes this.