Jump to content

SEARCH FOR VALUES USING SUBSTR AND EXPLODE


abhilash

Recommended Posts

this is the piece of code

 

$cookie = explode("\r\n", $raw_value);

if (substr($cookie, 0, 8) == 'Cookie:') {

return substr($cookie_split_sent, 8);

}

return "";

}

 

What I need this code to do is get the raw value from and xml file and split it and store it in $cookie. Next I want to extract only that part of text which begins after the word "Cookie". If there is any value return the value to the function if not return blank. However am getting the following error

 

Warning: substr() expects parameter 1 to be string, array given in

 

I know its expecting a string value. But am heading at a dead end now. Am pretty new to php. Any help would be highly appreciated

this is the piece of code

 

$cookie = explode("\r\n", $raw_value);

if (substr($cookie, 0, 8) == 'Cookie:') {

return substr($cookie_split_sent, 8);

}

return "";

}

 

What I need this code to do is get the raw value from and xml file and split it and store it in $cookie. Next I want to extract only that part of text which begins after the word "Cookie". If there is any value return the value to the function if not return blank. However am getting the following error

 

Warning: substr() expects parameter 1 to be string, array given in

 

I know its expecting a string value. But am heading at a dead end now. Am pretty new to php. Any help would be highly appreciated

return substr($cookie_split_sent, 8);

You do not tell us what is in this variable. which substr is throwing the error? - the first I guess, not this one

 

It has to be a string not an array for substr to work as you want. That is what the error message is saying. $cookie[0] may be a string containing the first line of raw_value though.

 

The thing to do is to print out all variables and see what is in them. Is it what you expect? Put a literal 'Cookie' into a variable and run with that to get the code working first, then let it run with the real values. One step at a time and you will get there quicker than trying to do it all at once ! really... try it!

 

 

the $raw_value contains http <request> and <response>. This is what I want from the code. Search for Cookie parameter from the request and response and leaving the text "Cookie:" pass everything else to the database. I think  I know what to do but am not quite getting the foreach statement to work to do a loop through the array and find cookie and return value.

 

Hope this helps. Thanks for the help

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.