It is over extending the div because there is no break in the url.(not just Safari)
You can either set the .twitterfeed to overflow:hidden; which would just hide anything wider but not look so great OR you could use php to truncate the url.
For example(if you can edit code comfortably):
$url_length = strlen($the_url);
if ( $url_length > 15 ) {
$url_length_trunc = substr($the_url, 0, 14);
$url_length_trunc = $url_length_trun . '...';
}
Then simply use <?php echo $url_length_trunc; ?> where you want the link displayed.
Note: “15” Is the number of characters you will have displayed before adding “…”.
Hi racer x thanks for the reply –
I’m familiar with php but still learning the environment –
would you mind if I ask : where would I place the above code –
$url_length = strlen($the_url);
if ( $url_length > 15 ) {
$url_length_trunc = substr($the_url, 0, 14);
$url_length_trunc = $url_length_trun . '...';
}
and then where where would the
<?php echo $url_length_trunc; ?> go
the reason I ask is because this is the php code which is generating the twitter feed onto the page – and this coding is sitting in the
.twitterfeed -DIV
<?php
$username = "yo_maggie";
$num = 1;
$feed = "http://search.twitter.com/search.json?q=from:" . $username . "&rpp=" . $num;
$newfile = dirname(__FILE__)."/twitternew.json";
$file = dirname(__FILE__)."/twitter.json";
copy($feed, $newfile);
$oldcontent = @file_get_contents($file);
$newcontent = @file_get_contents($newfile);
if($oldcontent != $newcontent) {
copy($newfile, $file);
}
$tweets = @file_get_contents($file);
$tweets = json_decode($tweets);
echo "<ul>";
for($x=0;$x<$num;$x++) {
$str = ereg_replace("<a href="http://codex.wordpress.org/:alpha:">:alpha:</a>+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\">\</a>", $tweets->results[$x]->text);
$pattern = '/[#|@][^\s]*/';
preg_match_all($pattern, $str, $matches);
foreach($matches[0] as $keyword) {
$keyword = str_replace(")","",$keyword);
$link = str_replace("#","%23",$keyword);
$link = str_replace("@","",$keyword);
if(strstr($keyword,"@")) {
$search = "<a href=\"http://twitter.com/$link\">$keyword</a>";
} else {
$link = urlencode($link);
$search = "<a href=\"http://twitter.com/#search?q=$link\" class=\"grey\">$keyword</a>";
}
$str = str_replace($keyword, $search, $str);
}
echo "<li>".$str."</li>\n";
}
echo "</ul>";
?>
Thanks again hope this makes sense.
Hi racer x the code below is what’s being used to generate the twitter feed on the page. Would I use the code you provided along with it or could I edit some area in the code provided where it would assist in making the link break if its too long?
thanks again for the assistance.
<?php
$username = "yo_maggie";
$num = 1;
$feed = "http://search.twitter.com/search.json?q=from:" . $username . "&rpp=" . $num;
$newfile = dirname(__FILE__)."/twitternew.json";
$file = dirname(__FILE__)."/twitter.json";
copy($feed, $newfile);
$oldcontent = @file_get_contents($file);
$newcontent = @file_get_contents($newfile);
if($oldcontent != $newcontent) {
copy($newfile, $file);
}
$tweets = @file_get_contents($file);
$tweets = json_decode($tweets);
echo "<ul>";
for($x=0;$x<$num;$x++) {
$str = ereg_replace(":alpha:+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\">\</a>", $tweets->results[$x]->text);
$pattern = '/[#|@][^\s]*/';
preg_match_all($pattern, $str, $matches);
foreach($matches[0] as $keyword) {
$keyword = str_replace(")","",$keyword);
$link = str_replace("#","%23",$keyword);
$link = str_replace("@","",$keyword);
if(strstr($keyword,"@")) {
$search = "<a href=\"http://twitter.com/$link\">$keyword</a>";
} else {
$link = urlencode($link);
$search = "<a href=\"http://twitter.com/#search?q=$link\" class=\"grey\">$keyword</a>";
}
$str = str_replace($keyword, $search, $str);
}
echo "<li>".$str."</li>\n";
}
echo "</ul>";
?>