Need help converting HTML Special Characters into character codes

Discussion in 'PHP' started by lokielookies, Feb 12, 2009.

  1. #1
    I have a problem on my new video site, for which videos are pulled from YouTube.

    It appears that for one video+description, there's <a href> tag that is opened, but not termintaed. (line 266, col 347 (of the page source, not the internal code)

    I was told to convert HTML Special Characters into character codes instead before writing it to the browser.

    Unfortunately, I know nothing abot PHP, so I have no idea what to do.



    :(
     
    lokielookies, Feb 12, 2009 IP
  2. tihan

    tihan Active Member

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    You have to find the variable (beginning with $) of the description, and insert

    $variable_name = htmlspecialchars($variable_name);

    row before display it (search echo/print commands).
     
    tihan, Feb 12, 2009 IP
  3. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #3
    I can't really find the variable :rolleyes:

    Based on the piece of code below, I assume it is $parse_desc
    ?

    // Make description short
    
    		$parse_desc=explode(" ",$line['content']); 
    		if(count($parse_desc)>25){
    			$line['content']="";
    			for($p=0;$p<25;$p++){$line['content'].=$parse_desc[$p]." ";}
    			$line['content']=trim($line['content'])."...";
    
    		}
    PHP:
     
    lokielookies, Feb 12, 2009 IP
  4. tihan

    tihan Active Member

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    try

    $line['content'] = htmlspecialchars($line['content']);
     
    tihan, Feb 12, 2009 IP
  5. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #5
    Call me dumb, but I can't get it to work.

    tihan, would you mind doing it for me?
     
    lokielookies, Feb 14, 2009 IP
  6. tihan

    tihan Active Member

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #6
    Based on the code above, if you copy my line after the code, it should work. If it's not working I have no idea what is the problem, sorry.
     
    tihan, Feb 14, 2009 IP
    lokielookies likes this.
  7. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #7
    It did work - I only had to be a bit more patient to see the result of the added code.

    Thanks a whole lot! :D
     
    lokielookies, Feb 14, 2009 IP
  8. dowhile

    dowhile Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #8
    Maybe you should also run striptags function, but since this function have some issues the best way is to process description is with preg_replace function.

    Example:

    $dsc = preg_replace('<[^<>]+?', ' ', $dsc);

    Now you will get this:
    some text
    instead of this:
    <a href ..> some text

    But this will also remove all tags that are presented in text like bold (<b></b>), or italic (<i></i>).
     
    dowhile, Feb 14, 2009 IP