Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate letters and digits from a string in php

Tags:

I have a string which is combination of letters and digits. For my application i have to separate a string with letters and digits: ex:If my string is "12jan" i hav to get "12" "jan" separately..

like image 466
sandeep Avatar asked Nov 30 '10 06:11

sandeep


People also ask

How do I split a character in a string in PHP?

PHP | str_split() Function The str_split() is an inbuilt function in PHP and is used to convert the given string into an array. This function basically splits the given string into smaller strings of length specified by the user and stores them in an array and returns the array.

How can I split a string into two parts in PHP?

PHP | explode() Function explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs.

How do I slice a string in PHP?

The substr() function used to cut a part of a string from a string, starting at a specified position. The input string. Refers to the position of the string to start cutting. A positive number : Start at the specified position in the string.


1 Answers

$numbers = preg_replace('/[^0-9]/', '', $str); $letters = preg_replace('/[^a-zA-Z]/', '', $str); 
like image 139
Mike C Avatar answered Oct 27 '22 11:10

Mike C