janim Posted September 15, 2007 Share Posted September 15, 2007 hello all ! i want to take part of text from mysql let's say my page title is : $title="php is the most common language for dynamic web pages and the most popular one"; if i want to take part of these sentence like the first 5 words to be like this " php is the most common language..." how can i do this >>Form Database << Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/ Share on other sites More sharing options...
teng84 Posted September 15, 2007 Share Posted September 15, 2007 you can try array (explode function) $x= explode(' ' ,'tst df sf dsfs ff df d df df d '); foreach($x as $key=> $val) { if ($key % 5 == 0){ echo '<br>'; } echo $val; } or foreach($x as $key=> $val) { if ($key % 5 == 0){ echo '......'; break; } echo $val; } edited... or string function note: not tested but that should work Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348761 Share on other sites More sharing options...
janim Posted September 15, 2007 Author Share Posted September 15, 2007 ya teng84 do you mean like this $til=$qry['title']; $limit=explode(' ',$til); foreach($limit as $key=> $val) { if ($key % 5 == 0){ echo $limit; break; } echo $val; the result is 'Array' just these word why Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348781 Share on other sites More sharing options...
Jessica Posted September 15, 2007 Share Posted September 15, 2007 because it is an array. You could also use substr and strpos. Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348791 Share on other sites More sharing options...
janim Posted September 15, 2007 Author Share Posted September 15, 2007 thank you very much jesirose just one more qustion how can i know what is the last id in mysql Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348798 Share on other sites More sharing options...
Jessica Posted September 15, 2007 Share Posted September 15, 2007 the last id of what? the last inserted? mysql_insert_id() Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348799 Share on other sites More sharing options...
janim Posted September 15, 2007 Author Share Posted September 15, 2007 i think that this function is working but i want to use it in my index page u c ? to start pulling data from database so i don't wanna use while and order by id asc i want the last inserted id in my index page can be done ?like this include("config.php"); mysql_connect($server, $datauser, $datapass) or die (mysql_error()); $last_id=mysql_insert_id(); $result = mysql_db_query($database, "select * from $table where id='$last_id'") or die (mysql_error()); if (mysql_num_rows($result)) { $qry = mysql_fetch_array($result); echo $last_id; . . . echo $qry['title']; there is no id shown in the result and no title :-\ Quote Link to comment https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/#findComment-348812 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.