Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isolate substring at end of string after a specific substring

My query generates a result set of UID values which looks like:

855FM21
855FM22
etc

I want to isolate the last number from the UID which it can be done by splitting the string.

How to split this string after the substring "FM"?

like image 206
Akhil P M Avatar asked Oct 09 '14 08:10

Akhil P M


2 Answers

To split this string after the sub string "FM", use explode with delimiter as FM. Do like

$uid = "855FM22";
$split = explode("FM",$uid);
var_dump($split[1]);
like image 77
Mithun Satheesh Avatar answered Sep 18 '22 22:09

Mithun Satheesh


You can use the explode() method.

<?php
$UID = "855FM21";
$stringParts = explode("FM", $UID);

$firstPart  = $stringParts[0]; // 855
$secondPart = $stringParts[1]; // 21

?>
like image 22
hfrahmann Avatar answered Sep 19 '22 22:09

hfrahmann