denoteone Posted April 8, 2009 Share Posted April 8, 2009 I have a variable that contains a string. I need to search for a word in the variable if that word is present I need to make a new variable that contains a different part of that string can anyone help me with this? I hope I don't have to use regex. $fp = [Querying whois.arin.net] [Redirected to whois.ripe.net:43] [Querying whois.ripe.net] I want to check to see if the word "Redirected" is in the variable. if (strpos($fp,"Redirected") is true){ $newserver = I need to get the string that is within the quotes [Querying whois.arin.net] [Redirected to whois.ripe.net:43] [Querying "whois.ripe.net"] } Quote Link to comment https://forums.phpfreaks.com/topic/153201-find-string-from-variable/ Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 What's wrong with using something similar to what you had? $fp = "[Querying whois.arin.net] [Reirected to whois.ripe.net:43] [Querying whois.ripe.net]"; if (strpos($fp,"Redirected")){ echo $fp; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153201-find-string-from-variable/#findComment-804772 Share on other sites More sharing options...
denoteone Posted April 8, 2009 Author Share Posted April 8, 2009 that looks like it will work but what about getting assigning part of that string to a new variable. so if the string is "[Querying whois.arin.net] [Reirected to whois.ripe.net:43] [Querying whois.ripe.net]" I need the data between the second instance of the word Querying to the 6th instance of the "]" symbol. Quote Link to comment https://forums.phpfreaks.com/topic/153201-find-string-from-variable/#findComment-804787 Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 I need the data between the second instance of the word Querying to the 6th instance of the "]" symbol. 6th instance, I only see 3... Sorry, I don't understand what that mean. Can you give an example? Quote Link to comment https://forums.phpfreaks.com/topic/153201-find-string-from-variable/#findComment-804790 Share on other sites More sharing options...
denoteone Posted April 8, 2009 Author Share Posted April 8, 2009 6th instance, I only see 3... Sorry, I don't understand what that mean. Can you give an example? sorry i was counting both "[" and "]" I need something like this $fp = "[Querying whois.arin.net] [Reirected to whois.ripe.net:43] [Querying whois.ripe.net]"; $newfp = (getstring($fp,between 2nd Querying and 3rd ]); echo $newfp; output whois.ripe.net Quote Link to comment https://forums.phpfreaks.com/topic/153201-find-string-from-variable/#findComment-804794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.