abhilash Posted March 18, 2011 Share Posted March 18, 2011 this is the piece of code $cookie = explode("\r\n", $raw_value); if (substr($cookie, 0, == 'Cookie:') { return substr($cookie_split_sent, ; } 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 Link to comment https://forums.phpfreaks.com/topic/231007-search-for-values-using-substr-and-explode/ Share on other sites More sharing options...
abhilash Posted March 18, 2011 Author Share Posted March 18, 2011 this is the piece of code $cookie = explode("\r\n", $raw_value); if (substr($cookie, 0, == 'Cookie:') { return substr($cookie_split_sent, ; } 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 Link to comment https://forums.phpfreaks.com/topic/231007-search-for-values-using-substr-and-explode/#findComment-1189148 Share on other sites More sharing options...
kenrbnsn Posted March 18, 2011 Share Posted March 18, 2011 What's in the variable $raw_value? The explode() function returns an array. Please post your code between tags. Ken Link to comment https://forums.phpfreaks.com/topic/231007-search-for-values-using-substr-and-explode/#findComment-1189152 Share on other sites More sharing options...
ocpaul20 Posted March 18, 2011 Share Posted March 18, 2011 return substr($cookie_split_sent, ; 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! Link to comment https://forums.phpfreaks.com/topic/231007-search-for-values-using-substr-and-explode/#findComment-1189174 Share on other sites More sharing options...
abhilash Posted March 18, 2011 Author Share Posted March 18, 2011 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 Link to comment https://forums.phpfreaks.com/topic/231007-search-for-values-using-substr-and-explode/#findComment-1189252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.