SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_replace function

    So I'm trying to get this script to replace my <strong>text</strong> with text.

    But I can't this code to do it:

    Code:
    function html_format($str) 
    {
    	$str = htmlentities($str, ENT_COMPAT, 'UTF-8'); 
    
         $simple_search = array(  
                    '/\<strong\>(.*?)\<\/strong\>/is' ,                
                    );
    	
    	$simple_replace = array(
                    '<B>$1</B>',        
                    );   
    				
    				    // Do simple BBCode's
        $str = preg_replace ($simple_search, $simple_replace, $str);
    
           return $str;
    }
    What is wrong with my code?

  2. #2
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by FCC
    But I can't this code to do it:

    What is wrong with my code?
    Please explain what trouble you are having.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    this will help you:

    $line ="<strong>text</strong>";

    // clean the html tags
    preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", $line ,$out, PREG_PATTERN_ORDER);

    // the result
    $result = $out[1][0].$out[1][1];

    print $result; // out put is text

    thanks


Bookmarks

Posting Permissions

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