PHP: Extract Alphanumeric Sequences from a String
Posted on October 5, 2008, Filled under PHP,
Bookmark it
This short snippet is useful if you need to extract alphanumeric sequences (characters) from a string:
function extract_alphanumeric_sequences($string)
{
preg_match_all('/([a-zA-Z0-9]+)/', $string, $match);
return $match[0];
}
$string = 'Suspendisse 354 65pretium eros ut 43564 mauris. Integer in lacus quis est dignissim posuere. Aenean dui. &$#^@ %$ 94375 Mauris non turpis sit amet nunc imperdiet varius.';
$alpha_array = extract_alphanumeric_sequences($string);
echo '<pre>'; print_r($alpha_array); echo "</pre>";
Output:
Array
(
[0] => Suspendisse
[1] => 354
[2] => 65pretium
[3] => eros
[4] => ut
[5] => 43564
[6] => mauris
[7] => Integer
[8] => in
[9] => lacus
[10] => quis
[11] => est
[12] => dignissim
[13] => posuere
[14] => Aenean
[15] => dui
[16] => 94375
[17] => Mauris
[18] => non
[19] => turpis
[20] => sit
[21] => amet
[22] => nunc
[23] => imperdiet
[24] => varius
)
Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!
- October 5, 2008
- article by Gabriel C.
- Leave a reply!
Sponsors
Related Posts
-
PHP: Extract Alphabetical Sequences from a Stringat October 5, 2008
-
PHP: Match Non-Alphanumeric Characters from a Stringat October 5, 2008
-
PHP: How to extract numbers from a string (text)at October 5, 2008 with 2 comments
-
Shorten a string (text)at September 3, 2008 with 2 comments
-
How to extract username from an e-mail address stringat September 5, 2008 with 2 comments
