ffxpwns Posted March 31, 2012 Share Posted March 31, 2012 When I try to run the code below with if ( $user->uid ) it works just dandy. But if I use if ( !$user->uid ) it puts the number one a little bit below my truncated paragraph. It only started doing this after I put the $login = print("Log in to see full article!"); . It worked normally (besides the fact that it didn't say log in to see full article) And for description, I have 400 words of Lorem Ipsum, but you guys dont need to see that so I put elipses. <head> <?php // this signifies how to truncate function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } ?> <title>truncate test</title> </head> <body> <?php $description = 'Lorem. ipsum dolor sit amet...'; // This makes it so it only applies to non logged in users if ( !$user->uid ) { //Replace 'XXX' with your number (Probably 500) $description = myTruncate($description, xxx); $login = print("Log in to see full article!"); } echo "<p>$description</p>"; echo "<p>$login</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/260097-truncate-script-is-putting-in-unwanted-numbers/ Share on other sites More sharing options...
ffxpwns Posted March 31, 2012 Author Share Posted March 31, 2012 When I use the $user part, it works as in it displays the full article. and not the $login. The number is the only problem and only occurs when I use the !$user Quote Link to comment https://forums.phpfreaks.com/topic/260097-truncate-script-is-putting-in-unwanted-numbers/#findComment-1333098 Share on other sites More sharing options...
jcbones Posted March 31, 2012 Share Posted March 31, 2012 Line: $login = print("Log in to see full article!"); Should be: $login = "Log in to see full article!"; Quote Link to comment https://forums.phpfreaks.com/topic/260097-truncate-script-is-putting-in-unwanted-numbers/#findComment-1333106 Share on other sites More sharing options...
ffxpwns Posted March 31, 2012 Author Share Posted March 31, 2012 Line: $login = print("Log in to see full article!"); Should be: $login = "Log in to see full article!"; Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/260097-truncate-script-is-putting-in-unwanted-numbers/#findComment-1333111 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.