How To Become The Showtime Give-And-Take Of A String/Sentence Inwards Php?

There is a string business office (strtok) which tin hold upwards used to separate a string into smaller strings (tokens) based on unopen to separator(s). For the purposes of this thread, the offset give-and-take (defined equally anything earlier the offset infinite character) of Test me more can hold upwards obtained by tokenizing the string on the infinite character.
<?php $value = "Test me more"; echo strtok($value, " "); // Test ?>
For to a greater extent than details in addition to examples, meet the strtok PHP manual page.

Alternative solutions

$myvalue = 'Test me more'; echo strstr($myvalue, ' ', true); // volition impress Test
echo current(explode(' ',$myvalue)); // volition impress Test
$myvalue = 'Test me more'; $arr = explode(' ',trim($myvalue)); echo $arr[0]; // volition impress Test
$string = ' Test me to a greater extent than '; preg_match('/\b\w+\b/i', $string, $result);  echo $result; // volition impress Test   /* You could occupation [a-zA-Z]+ instead of \w+ if wanted exclusively alphabetical chars. */ $string = ' Test me to a greater extent than '; preg_match('/\b[a-zA-Z]+\b/i', $string, $result);  echo $result; // volition impress Test
Ref: http://stackoverflow.com/questions/2476789/how-to-get-the-first-word-of-a-sentence-in-php

Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

Removing The Index.Php File From Url Inward Codeigniter

What Are The Main Components of a Computer System

Delete Daily Doppler E-Mail Spam From An Iphone [Fix]