Jump to content

[SOLVED] Getting Imput String to Wrap


bospa

Recommended Posts

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?

 

Board1.gif

Link to comment
https://forums.phpfreaks.com/topic/147929-solved-getting-imput-string-to-wrap/
Share on other sites

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.

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>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.