web_master Posted April 19, 2009 Share Posted April 19, 2009 Hi, I want to reload a text from database, but I want to "echo" only the first word? In database is: "Fox on the run" and I want to print on screen only first word: "Fox" From every rows only first word... How can I do this with PHP? $request['headline']; thnxs T Link to comment https://forums.phpfreaks.com/topic/154758-solved-reload-first-word-only/ Share on other sites More sharing options...
KPH71 Posted April 19, 2009 Share Posted April 19, 2009 <?php $array = explode(" ", $variable); if (count($array)!=0) { $theword = $array[0]; } else { $theword = "Not Found"; } ?> Link to comment https://forums.phpfreaks.com/topic/154758-solved-reload-first-word-only/#findComment-813823 Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 you can try splitting the sentance then exploding... <?php $sent = 'Fox Racing Is Nice!'; $frags = explode(' ',$sent); // splits string at spaces.... echo $frags[0]; //echos only 1st fragment or first word Link to comment https://forums.phpfreaks.com/topic/154758-solved-reload-first-word-only/#findComment-813824 Share on other sites More sharing options...
web_master Posted April 19, 2009 Author Share Posted April 19, 2009 you can try splitting the sentance then exploding... <?php $sent = 'Fox Racing Is Nice!'; $frags = explode(' ',$sent); // splits string at spaces.... echo $frags[0]; //echos only 1st fragment or first word ITS WORK, GREAT, THANX! Link to comment https://forums.phpfreaks.com/topic/154758-solved-reload-first-word-only/#findComment-813828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.