0

I have the following string:

"@String RT @GetThisOne: Natio"

How can I get "GetThisOne" from this string?

3
  • You really need to expand on your problem statement. Are you trying to get the name after RT? Could there be more than one? Etc. Commented Nov 11, 2011 at 17:22
  • 2
    You need to be more specific... will the position of your text change from string to string? What you want is probably going to be a regular expression... Commented Nov 11, 2011 at 17:23
  • Do you mean taht you want to extract "GetThisOne" from a string ? Do you mean tou need to extract the string between @ and : ? What have you try so far ? What doesn't work ? Commented Nov 11, 2011 at 17:23

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the substr function.

Comments

1

Find "@" position, and calculate position of ":" after the "@" found.

$at = strpos($string,'@');

substr($string,$at,strpos($string,':',$at)-$at);

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.