Reputation: 23352
I have the following string:
"@String RT @GetThisOne: Natio"
How can I get "GetThisOne" from this string?
Upvotes: 0
Views: 200
Reputation: 41885
You can use preg_match like this:
<?php
$string = "@String RT @GetThisOne: Natio";
preg_match('/@.*@([A-Za-z]*)/', $string, $matches);
echo $matches[1]; // outputs GetThisOne
Here, the pattern is the folowing: find an numeric string after the second @
.
Ideone example.
Upvotes: 2
Reputation: 12149
You could always try php explode function
$string = "@String RT @GetThisOne: Natio"
$arr = explode('@', $string);
if(is_array($arr) && count($arr)>0)
{
echo $arr[0]."\n";
echo $arr[1];
}
will echo out
String RT
GetThisOne: Natio
Upvotes: 1
Reputation: 254
Find "@" position, and calculate position of ":" after the "@" found.
$at = strpos($string,'@');
substr($string,$at,strpos($string,':',$at)-$at);
Upvotes: 1