HI everyone I want to get string last word i.e Programming Languages Books > New, Used & Rental Textbooks > Computer Science > Programming Languages is there any easy solution i tried explode but did not understand how it work properly because i have other strings Books > Computers & Technology > Computer Science Books > Computers & Technology > Databases Books > Computers & Technology > Hardware > Design & Architecture Books > Computers & Technology > Programming > Languages & Tools > Lisp Books > Computers & Technology > Software Books > Education & Reference Books > New, Used & Rental Textbooks > Computer Science > Database Storage & Design My target is getting Computer Science Databases Design & Architecture Lisp Software Education & Reference Database Storage & Design
Mhhh... let's see...I assume that every line is stored in an array $library = array( "Books > Computers & Technology > Computer Science", "Books > Computers & Technology > Databases", "Books > Computers & Technology > Hardware > Design & Architecture", "Books > Computers & Technology > Programming > Languages & Tools > Lisp", "Books > Computers & Technology > Software", "Books > Education & Reference", "Books > New, Used & Rental Textbooks > Computer Science > Database Storage & Design" ); foreach($library as $string) { $split = explode(" > ", $string); echo $split[count($split)-1]."<br />"; } PHP: Stackoverflow helped a lot http://stackoverflow.com/questions/11029447/how-to-get-last-string-in-sentences-using-php Code (markup):
hi your help is appropriated but how i can convert all string into one variable when out put Computer Science Databases Design & Architecture Lisp Software Education & Reference Database Storage & Design like $a='Computer Science,Databases,Design & Architecture,Lisp,Software,Education & Reference,Database Storage & Design';
Mhhh... $section = array(); $library = array( "Books > Computers & Technology > Computer Science", "Books > Computers & Technology > Databases", "Books > Computers & Technology > Hardware > Design & Architecture", "Books > Computers & Technology > Programming > Languages & Tools > Lisp", "Books > Computers & Technology > Software", "Books > Education & Reference", "Books > New, Used & Rental Textbooks > Computer Science > Database Storage & Design" ); foreach($library as $string) { $split = explode(" > ", $string); $section[] = $split[count($split)-1]; } $result = implode(", ", $section); echo $result; PHP: Which results in this Computer Science, Databases, Design & Architecture, Lisp, Software, Education & Reference, Database Storage & Design Code (markup):
Simpler $str = explode(' ',$your_string); echo end($str); PHP: Oh i didnt know it was an array, but this will get the last word in a sentance etc... Will leave it may be useful for someone else.
@ronnie403 -- look at the data closer, they don't want just the last WORD, they want the last SECTION. (though the OP's broken Engrish is most likely to blame for your thinking such) -- Doesn't want just "Science", wants "computer science", doesn't want just "Design", they want "Database Storage & Design" GMF's answer is ok, but would benefit from your suggestion of 'end' as well as building the comma delimited list inside the loop instead of with implode. $library = array( 'Books > Computers & Technology > Computer Science', 'Books > Computers & Technology > Databases', 'Books > Computers & Technology > Hardware > Design & Architecture', 'Books > Computers & Technology > Programming > Languages & Tools > Lisp', 'Books > Computers & Technology > Software', 'Books > Education & Reference', 'Books > New, Used & Rental Textbooks > Computer Science > Database Storage & Design' ); $result=''; foreach ($library as $string) $result .= end(explode(' > ', $string)).', '; echo trim($result,', '); Code (markup): ... and of course my nitpick of getting rid of the stupid malfing double quotes
Lol i was gonna post the same thing you posted after i realised it in my first post, but you already posted it