Anil Sharma
Anil Sharma

Reputation: 125

how to get word from string using preg_match_all

I have multiple string which contains HP16SDA305009, HP16JDA305009,HP16SWA305009

I need to get only SDA, JDA or SWA how can I achieve that

Upvotes: 1

Views: 32

Answers (2)

Anil Sharma
Anil Sharma

Reputation: 125

$a= 'HP16JDA305009';

        $char = substr($a, 4, -3);

        echo $gen = substr($char, 0, 3);

Upvotes: 0

Vikas Gautam
Vikas Gautam

Reputation: 978

$var = "HP16SDA305009";

 $result = substr($var, 0, -6);

echo $result = substr($result, 4, 3);

Upvotes: 1

Related Questions