gamefreak13 Posted May 22, 2008 Share Posted May 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/106696-urgent-simple-decodeanalyzefilter-text-with-php/ Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 To the top. Link to comment https://forums.phpfreaks.com/topic/106696-urgent-simple-decodeanalyzefilter-text-with-php/#findComment-547050 Share on other sites More sharing options...
dungareez Posted May 22, 2008 Share Posted May 22, 2008 $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 Link to comment https://forums.phpfreaks.com/topic/106696-urgent-simple-decodeanalyzefilter-text-with-php/#findComment-547099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.