Problem with escaping special characters

Discussion in 'PHP' started by threehundred, Jun 21, 2006.

  1. #1
    I'm a novice with PHP and I have a script I'm trying to use that doesn't parse correctly. I've attached the PHP file here. The problem is with the non-escaping of the > and sometimes " The resulting page is displayed below:

    "; } $ListingTable .= "\n\t"; $ListingTable .= "$a1[city], $a1[state], $a1[address] $sub\n\t"; $ListingTable .= "$a1[rooms] br, $a1[bathrooms] ba"; $MyPrice = number_format($a1[Price], 2, ".", ","); $ListingTable .= "\n\t$$MyPrice\n"; $ListingTable .= "\n"; } $ListingTable .= ""; } /////////////////////////////////////////////////////////// ///////////// top 10 /////////////////////////////////////////////////////////// $q1 = "select * from re2_listings, re2_agents, re2_priority where re2_listings.AgentID = re2_agents.AgentID and re2_agents.PriorityLevel = re2_priority.PriorityLevel and re2_agents.AccountStatus = 'active' order by visits desc limit 0,9 "; $r1 = mysql_query($q1) or die(mysql_error()); $lrows = mysql_num_rows($r1); if($lrows > '0') { $TopTable .= "\n"; while($a1 = mysql_fetch_array($r1)) { $TopTable .= " \n\t"; if($a1[PriorityLevel] > '1') { $sub = "$a1[PriorityName]"; } else { $sub = ""; } $TopTable .= "\n\t "; if(!empty($a1[image])) { $TopTable .= ""; } $TopTable .= " \n\t"; $TopTable .= " $a1[city], $a1[state], $a1[address] $sub \n\t"; $TopTable .= " $a1[rooms] br, $a1[bathrooms] ba"; $MyPrice = number_format($a1[Price], 2, ".", ","); $TopTable .= " \n\t $$MyPrice \n"; $TopTable .= " 
    \n"; } $TopTable .= " "; } require_once("templates/IndexTemplate.php"); echo "
    "; require_once("templates/FooterTemplate.php"); ?> 
    Code (markup):

    How do I correct this part of the code? In this instance, I reversed the equation so that i could use <, but in some cases in the script, doing that will not work. Any suggestions?
     

    Attached Files:

    threehundred, Jun 21, 2006 IP
  2. threehundred

    threehundred Member

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    I've tried changing the > symbols to \> to no avail. From what I'm reading, that should work. However, I must be doing something wrong, because I can't get that to work. Is it possible that PHP is not set up correctly on my server?
     
    threehundred, Jun 22, 2006 IP
  3. sadcox66

    sadcox66 Spirit Walker

    Messages:
    496
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perhaps your included templates are not ending with ?>
     
    sadcox66, Jun 22, 2006 IP
  4. threehundred

    threehundred Member

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    I figured out most of the problems were with the php files beginning with <? instead of <?php. There were a few other problems, but i'm getting most of them worked out. Thanks for your response sadcox66, its greatly appreciated.
     
    threehundred, Jun 22, 2006 IP
  5. ClearVisionDesigns.co.uk

    ClearVisionDesigns.co.uk Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    php files should work fine with <? but it is always best for use <?php for compatibility reasons.
     
  6. threehundred

    threehundred Member

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #6
    I thought that <? should work. I suppose I will always use <?php from now on.
     
    threehundred, Jun 22, 2006 IP
  7. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I find it extremnely annoying when programmers assume php files will work with <?

    I have yet to have a Linux of Windows install of PHP where that short form works.

    Coders need to work harder at sticking to standards and use methods which will work, instead of those which "should". I still see it in people's php code. Functions which and methods which are due to be deprecated continue to used, despitre compatibility and/or security issues.
     
    clancey, Jun 22, 2006 IP