bospa Posted March 4, 2009 Share Posted March 4, 2009 I’m new to php and have added a simple code to display where visitor came from. <?php $referred = $_SERVER['HTTP_REFERER']; print "<strong>You Got Here From: (if you clicked on a link to get here)</strong>:<br />\n"; if ($referred == "") { print "Page was directly requested"; } else { print "$referred"; } ?> Problem is if the string is too long it goes off the page. Is there a simple way to get this to wrap if it reaches a certain point on the page? Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/ Share on other sites More sharing options...
rhodesa Posted March 4, 2009 Share Posted March 4, 2009 you could use http://us3.php.net/manual/en/function.wordwrap.php Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/#findComment-776387 Share on other sites More sharing options...
bospa Posted March 4, 2009 Author Share Posted March 4, 2009 Thanks for the fast reply. I looked at the code and I'm not sure where to place it the code I already have. Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/#findComment-776393 Share on other sites More sharing options...
Zhadus Posted March 4, 2009 Share Posted March 4, 2009 The function that rhodesa posted should work great, but keep in mind that not all fonts are monospace fonts, so test it with an all caps link, or force all lowercase on the link. Edit: In response to your question, you run the function with $referred as the input and return it into $referred. Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/#findComment-776395 Share on other sites More sharing options...
47.46.45 Posted March 4, 2009 Share Posted March 4, 2009 Zhadus is spot on... should look something like this. I think. <?php $referred = $_SERVER['HTTP_REFERER']; $referred = wordwrap($referred, 20, "<br />\n", true); print "<strong>You Got Here From: (if you clicked on a link to get here)</strong>:<br />\n"; if ($referred == "") { print "Page was directly requested"; } else { print "$referred"; } ?> Tweak that 20 to adjust how soon it wraps. For bonus points: else { echo "<a href=\"".$referred."\">".$referred."</a>"; } Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/#findComment-776397 Share on other sites More sharing options...
bospa Posted March 4, 2009 Author Share Posted March 4, 2009 Thank you all for the help and fast solution. Link to comment https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/#findComment-776411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.