Jump to content

find string from variable


denoteone

Recommended Posts

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"] 
}

Link to comment
https://forums.phpfreaks.com/topic/153201-find-string-from-variable/
Share on other sites

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.

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

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.