< symbol breaks a simple string .. Any workarounds ?

Discussion in 'PHP' started by Simple Link Media, Mar 5, 2011.

  1. #1
    Char list contains 89 symbols 
    [ 1 ] Adding random symbol: A
    [ 2 ] Adding random symbol: ^
    [ 3 ] Adding random symbol: <
    [ 4 ] Adding random symbol: r
    [ 5 ] Adding random symbol: -
    [ 6 ] Adding random symbol: d
    [ 7 ] Adding random symbol: 6
    [ 8 ] Adding random symbol: {
    Result: A^
    Code (markup):
    Char list contains 89 symbols 
    [ 1 ] Adding random symbol: A
    [ 2 ] Adding random symbol: U
    [ 3 ] Adding random symbol: m
    [ 4 ] Adding random symbol: ^
    [ 5 ] Adding random symbol: G
    [ 6 ] Adding random symbol: G
    [ 7 ] Adding random symbol: <
    [ 8 ] Adding random symbol: <
    Result: AUm^GG<<		 	
    Code (markup):
    As you see, whenever there's <, everything falls apart.
    The main thing I don't get it is why it does so and why doesn't it fail when there are 2 symbols in a row.

    ** It's the only symbol I have problems with.
    ** Don't ask for code - it's a simple function - an array, explode and for loop ..

    Any ideas ?
     
    Simple Link Media, Mar 5, 2011 IP
  2. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    u r adding these to something and < is getting in as a comparing < and not just bracket...
    Try using HTML ascii hex
     
    eleetgeek, Mar 5, 2011 IP
  3. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    AND...

    No code != workaround

    If you need workaround, you need to display code... and try to use words like 'please' :)
    Oh yea.... am being the big daddy here =)
     
    eleetgeek, Mar 5, 2011 IP
  4. dgreenhouse

    dgreenhouse Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're not mentioning how you're using the values in the array... Outputting to html, script, etc.?

    Try using ( &lt; or %3C or &#60; )

    You might also look into the functions:
    htmlspecialchars(), htmlentities(), and urlencode().
     
    dgreenhouse, Mar 5, 2011 IP
  5. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you - transforming it to a an ASCII representation did the job :)

    For the given case the problem have been solved but I'm still confused - why does it treat it as an operator when placed as a string ( double-quotes ) ?

    Really ? See above .. :p
     
    Simple Link Media, Mar 5, 2011 IP
  6. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6

    Lol ok.... :p

    'why does it treat it as an operator when placed as a string ( double-quotes ) ?'


    To find an answer for yourself and to learn it, run this:

    
    <?php
    $variable = "Yahoo";
    
    echo 'this is with single quotes: $variable';
    print_r '<br />';
    echo "this is with double quotes: $variable";
    ?>
    PHP:
    And u will see the difference :)

    Try using single quotes and let us all know here :)
     
    eleetgeek, Mar 5, 2011 IP
  7. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $sum = "1 + 2";
    PHP:
    Will the output be 3 ? No.

    Also, the thing is that I don't use any quotes at all - I just concatenate something ( variable ) to an already existing variable.

    ** I still don't get why does it fall apart instead of just skipping the given character ..
     
    Simple Link Media, Mar 6, 2011 IP