Currently I have an array something like this
[0] => IS-001 開花した才能「篠ノ之 箒」
From this, I would like to extract only the IS-001 part and leave the Japanese character behind to something like this
[0] => 開花した才能「篠ノ之 箒」
Normal preg_split I am using currently only for white space but it seems like having some issue on the 箒」 character to fall into next array. So I decided if only I can split those non Japanese characters out?
Use the re. split() method to split a string into text and number, e.g. my_list = re. split(r'(\d+)', my_str) .
Try this
echo preg_replace('/^[a-zA-Z0-9\-_]+/u','','IS-001 開花した才能「篠ノ之 箒」');
^
assert position at start of the string[a-zA-Z0-9\-_]
match a single character present in the list+
Between one and unlimited times, as many times as possible, giving back as needed u modifier
unicode: Pattern strings are treated as UTF-16.A solution to this is by using multibyte string functions.
So $char = substr($str, $i, 1);
will become $char = mb_substr($str, $i, 1, 'UTF-8');
and strlen($str)
will become mb_strlen($str, 'UTF-8')
.
$str="IS-001 開花した才能「篠ノ之 箒」";
$japanese = preg_replace(array('/[^\p{Han}?]/u', '/(\s)+/'), array('', '$1'), $str);
echo $japanese;
(or)
Remove latin letters and digits from string
$res = preg_replace('/[a-zA-Z0-9-]+/', '', $str);
echo $res;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With