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 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    71
    Thanks
    16
    Thanked 0 Times in 0 Posts

    removing html tags

    Hi experts ! i am trying to remove html tags around my html file.
    example code:
    Code:
    <div>
    <p>This is an image </p>
    <img src="http://image.info/200910/186336.jpg" border="0" alt="" /><br /><br />
    </div>
    when i use strip_tags it will remove everything and i will have only "This is an image" text left, is it possible that i can display the image link and it will sounded like this:
    Code:
    [img]http://image.info/200910/186336.jpg[/ img]
    so in my code it will display the paragraph with image below. Thanks for any support
    Regards

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    strip_tags() will remove the HTML.

    look in to BBCODE for the other purpose. i'll post some sample bb in a second

    PHP Code:
    function bb_code($text)

    $array=array( 
    "[b]" => "<b>",  
    "[/b]" => "</b>",  
    "[i]" => "<i>",  
    "[/i]" => "</i>"
    ":)" => "<img src='img/smilies/smile.gif' />",
    "[img]" => "<img src='",
    "[/img]" => "' />"

    // etc
    );  

    $bb_textstr_replace(array_keys($array), array_values($array), $text);  

    return 
    $bb_text;  


    that is if i understand you right
    Last edited by met; 11-03-2009 at 09:09 PM.

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    71
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thank you for taking time to look at my problem but this never did the trick, what i did is here. all html is in $content.
    Code:
     $content = str_ireplace($replacing, "*****", $content);
     $content =  strip_tags($content, '<img>');
     $patterns = '<img>';
     $replacement ='[img]';
     $content =  preg_replace($patterns, $replacement, $content);
    but again not result what i wanted, its not diplaying the images its showing code like this:
    Code:
    <[img] src="http://image.info/200910/186336.jpg" border="0" alt="" />
    I know i need to use some regular expressions there but i am not so familiar with it.
    Thanks for any help
    Last edited by Dshah; 11-03-2009 at 09:40 PM.


  •  

    Posting Permissions

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