Jump to content

Urgent & Simple: Decode/Analyze/Filter text with PHP


gamefreak13

Recommended Posts

I have some text and I need to use PHP to remove what I don't need.

 

For example:

 

catdogsnakepanda

 

I need to output only "snake".. but its all a big mess.. how do I sort/filter/crop/whatever the above text?

 

Specifically, I am trying to dissect this text (No I'm not fetching this from a url.. its just text). Unlike the above example, in this case (which is the real scenario) I will not know the friendid #.. (duh its what I'm trying to get).. so I cant use the typical php code to search for certain words or numbers.

 

someothersite.com/index.cfm?fuseaction=user.viewprofile&friendid=123123&MyToken=fe4a1bc9-e381-4b36-8408-bec0504b4a86

 

See where it says 123123? I need to input the above text and output only 123123.

 

The below code works great but it outputs both the authorID variable data and the messageID data.. but I only need the messageID one (for example)... so I think this is the right idea..

 

<?

$a = explode('&', "authorID=78171269&messageID=5829424801");

foreach($a as $key => $b)
{
$b = split('=', $b);
echo $b[1]."<br>";
}

?>

 

Which outputs

 

73137269

5829824891

 

This is so incredibly easy.. I know it is.. but I can't figure it out

 

Note: In the example I shortned the url for simplicity.

 

$var = "someothersite.com/index.cfm?fuseaction=user.viewprofile&friendid=123123&MyToken=fe4a1bc9-e381-4b36-8408-bec0504b4a86";

 

$stringStarts = (strpos($var, "friendid=") + 9; //the 9 just add the length of the search string to the strpos returned so you begin at the end of the search string

 

$stringEnds =  (strpos($var, "&MyToken");

 

$friendid = substr($var, $stringStarts, $stringEnds);

 

 

 

I am sure there is a more elegant way of doing it, but that should work.  Good luck

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.