Eejut Posted November 26, 2009 Share Posted November 26, 2009 Hi, here's my problem.. I have a php generated page with a hyperlink which opens in a new window echo "<tr><td><a onclick=\"window.open('http://www.***.com/page/options.php?user_id=$user_id&session_id=$session_id','options','width=590,height=200,toolbar=no,scrollbars=yes,resizable=yes,statusbar=no,directories=no,menubar=no,location=no');return false;\" href=\"\">$user_id</a></td></tr>"; The problem occurrs at options.php?user_id=$user_id The resulting hyperlink on the generated page adds a space to the user id after the "=" So when options.php loads.. it results in the user's id having an extra %20 at the beginning of their name Example.. The first page links to this.. http://www.***.com/page/options.php?user_id= Eejut&session_id=12345 When options.php loads it prints.. "This is %20Eejut's Options Page" I've tried using trim($user_id) before printing the hyperlink to the main page (that calls options.php) and the space still occurrs in the hyperlink Anyone know what's going wrong?? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/ Share on other sites More sharing options...
MadTechie Posted November 26, 2009 Share Posted November 26, 2009 Nothing wrong with that code. Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966192 Share on other sites More sharing options...
mrMarcus Posted November 27, 2009 Share Posted November 27, 2009 ya, code looks fine. let's see your usage of trim(). Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966199 Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2009 Share Posted November 27, 2009 Either your code that is setting $user_id is adding the space or you actually have a space in your data. Edit: In fact, I'm going guess you have some code that looks like this - $user_id = " {$row['user_id']}"; Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966207 Share on other sites More sharing options...
Eejut Posted November 27, 2009 Author Share Posted November 27, 2009 Here's the code that uses //get list of active members $activemembers = file('activemembers.txt'); if (!$activemembers) {echo 'ERROR: Unable to open file.<br>'; exit;} foreach ($activemembers as $key => $line) { rtrim($line, "\n"); if ($line != " ") { list($user_id, $iponfile, $timestamponfile, $coloronfile, $passwordonfile, $session_id) = explode("|", $line); trim($user_id); echo "<tr><td><a onclick=\"window.open('http://www.***.com/page/options.php?user_id=$user_id&session_id=$session_id','options','width=590,height=200,toolbar=no,scrollbars=yes,resizable=yes,statusbar=no,directories=no,menubar=no,location=no');return false;\" href=\"\">$user_id</a></td></tr>"; } } As can be seen, I've added trim before outputting the hyperlink, hoping it would solve the space problem.. but the problem still persists If I replace user_id=$user_id .. with something like .. user_id=hello .. the space vanishes Am I using trim correctly?.. I'll admit to not having checked properly yet Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966581 Share on other sites More sharing options...
Eejut Posted November 27, 2009 Author Share Posted November 27, 2009 Just checked and it's ok.. isn't it? All I can guess is.. could it be a server issue?! .. the session_id variable isn't effected, I'd have thought even if there's a gap in the data it'd get removed Unless there's an invisible character (such as a new line or something) to the left of the first variable that trim isn't removing?? I know I should use mysql or something.. I'm planning on learning that soon instead of relying on flat files.. lol Thanks for help to date and any more that can be given Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966583 Share on other sites More sharing options...
Eejut Posted November 27, 2009 Author Share Posted November 27, 2009 I've just tested something else here to check if there really is a gap being added before $user_id .. and there must be .. even after trim is used!! I added this bit of experimental, temporary code.. which follows the use of trim.. trim ($user_id); echo "the user id is$user_id"; The output should be "the user id isEejut" (assuming my name is the user id).. but it outputs.. "the user id is Eejut" I then tried this instead.. trim ($user_id); echo "$user_id$user_id"; .. and the output is "Eejut Eejut" (yes, with a space.. and id is repeated on the same line.. therefore it can't be a new line.. can it?!) So.. for some bizarre reason trim is either being ignored or isn't trimming.. why could this be?? lol Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-966598 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2009 Share Posted November 29, 2009 Find out what exactly is in $user_id - $arr = str_split($user_id); foreach($arr as $key => $value){ $val = ord($value); echo "Value of character at pos: $key, is $val<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-967536 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2009 Share Posted November 29, 2009 If this problem occurs with every user_id that is in your 'activemembers.txt' file, then you have a systematic problem with how you are producing or storing information in that file (and please be advised if the 'activemembers.txt' file is in a 'public' web accessible folder, that anyone who guesses the file name can browse to it and get all your member information.) If you cannot determine what character is present in the data that is causing the problem, make a test version of 'activemembers.txt' that only has one entry in it with dummy data. If the test file produces the symptom, attach the file to a post so that someone can examine what is actually in it. Best guess is that you are using a Word Processor to edit the file (or you copied/pasted from a Word Processor) and the underlying formatting characters that the Word Processor uses in the file is what is causing the problem. Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-967553 Share on other sites More sharing options...
Eejut Posted December 19, 2009 Author Share Posted December 19, 2009 Yes you're right.. I was printing an extra " " at the beginning of the text file every time a user posted a comment.. sorted out now.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/183068-hyperlink-is-adding-an-extra-gap-to-variable/#findComment-980630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.