0

$my_venue has data with space. For example= "nana nono". when I hoover to the link it gets cut off by the space. it works ok if there is no space.

<tr onmouseover="mouse_event(this, 'hlt');" onmouseout="mouse_event(this, '');">
    <?php
    $my_venue= $row['name'];

    echo "<td><a href= http://x.x.x.x:xx/JUNK/search_results.php?user-val=&venue-val=$my_venue&region-val=&lhversion-val=&releaseversion-val=&testtype-val=&api-val=&rate-val=&journaldate-val=&comments-val=&date-val=&record=%25>{$row['name']} </a></td>";
    echo "<td>{$row['region']} </td>";

Oh BTW, I need the space because I need to pass this info to the DB and in the DB the data does have the space

2
  • Try removing the spaces here {$row['name']} </a> and ['region']} </td>, see what that does. Commented Apr 16, 2013 at 16:14
  • @Fred - Avoiding all characters that need encoding is a really convolute approach... Commented Apr 16, 2013 at 16:15

2 Answers 2

2

You need to rawurlencode the values and quote the attribute. Especially the latter is something you should ALWAYS do. Browsers may be lenient with lack of encoding but a space in an unquoted argument will end it no matter what.

echo '<td><a href="http://x.x.x.x:xx/JUNK/search_results.php?user-val=&venue-val='.rawurlencode($my_venue).'&region-val=&lhversion-val=&releaseversion-val=&testtype-val=&api-val=&rate-val=&journaldate-val=&comments-val=&date-val=&record=%25">'.htmlspecialchars($row['name']).'</a></td>';

Oh, and in case mouse_event() adds a CSS class on hover: You can use the :hover CSS pseudo-class and do not need any JavaScript for this. Unless you need to support IE6 of course, but if that's the case your problem lies somewhere else anyway. :)

Sign up to request clarification or add additional context in comments.

8 Comments

No! Why would he ever need that? The PHP interpreter will do that when parsing the query string. Just like you never need to un-escape data you escaped to avoid SQL injection.
TS: Oh BTW, I need the space because I need to pass this info to the DB and in the DB the data does have the space
He does not need the space in the HTML. When he receives the variable he will have the space again.
&venue-val='.rawurlencode($my_venue).'&region-val= doesn't work. still cut off
No! I'm talking about the href attribute in HTML. Simply copy&paste the line from my answer.. it should work.
|
0
$my_venue = str_replace(' ', '%20', $row['name'])

4 Comments

That won't fix any other characters that need special handling.
urlencode in php wil change it in a +. Where other languages change it in %20
@S.Visser - And rawurlencode() will change it to %20. You choose.
@ÁlvaroG.Vicario thanks, did not know that. That should be an more clearer solution for the encode problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.