How to cut a group of words from a string

Discussion in 'PHP' started by eagle_eye, Nov 17, 2008.

  1. #1
    Hello,

    how to cut a certain group of words in a string, for example, "<img src='images/smiles/grin.gif</a>" from a reply. I am new to PHP, please help. Thanks very much in advance.
     
    eagle_eye, Nov 17, 2008 IP
  2. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    str_replace("(text to be removed without parenthesis)","","(original text without paranthesis)");
     
    xenous, Nov 17, 2008 IP
  3. eagle_eye

    eagle_eye Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow! You are on line? Thank you for this promt reply, but the other problem is that the everytime last words are all different, because they are dynamic, like:

    <img src='images/smiles/grin.gif</a>
    <img src='images/smiles/shy.gif</a>
    <img src='images/smiles/rose.gif</a>
    <img src='images/smiles/laugh.gif</a>
    <img src='images/smiles/smoking.gif</a>

    but really really thank you for the help so far!
     
    eagle_eye, Nov 17, 2008 IP
  4. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try this, just change $subject to the string you are using:

     
    mallorcahp, Nov 17, 2008 IP
  5. eagle_eye

    eagle_eye Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Wow!!! That's impressive!!! Thank you, mallorcahp, very much for your help!
     
    eagle_eye, Nov 17, 2008 IP
  6. eagle_eye

    eagle_eye Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi mallorcahp, I just realized that the replacing string is much longer than I found :), they are something like:
    "<img src='images/smiles/grin.gif' smilietext=':grin:' border='0' style='vertical-align:middle' alt=':grin:' title=':grin:' />"
    so it is very likely for me to make mistakes with a "/" or "\" more or less.... so logically, is it a better way to search for all what is inside the <img ... /> tag (including numbers) and replace them?
    I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank you for your help.
     
    eagle_eye, Nov 17, 2008 IP
  7. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This will kill all images in the message i think you want it ;)

    
    <?php
    $message = "Your message";
    $messagewithoutquotes=cleanQuotes($message);
    function cleanQuotes($message){
    $begin=strstr($message,'<img');
    $rest=strstr($begin,'/>');
    $interested=str_replace($rest,"",$begin);
    if(eregi("<img",$interested):
    cleanQuotes($interested);
    endif;
    return $interested
    }
    ?>
    
    PHP:
     
    xenous, Nov 17, 2008 IP