jmr3460 Posted April 5, 2011 Share Posted April 5, 2011 I need to break down this statement. I have tried to replace string and my code echos the line without the replaced string and with it. I don;t think that str_replace is how to do what I want to do. <?php $imap = imap_open("{abc.com:143}INBOX", "[email protected]", "**********"); $header = imap_header($imap, 1); $messages['body'] = imap_base64(imap_body($imap, 1)); foreach($messages as $message){ $message .= str_replace('Latitude:', ',Latitude: ', $message); echo $message; } ?> This code produces : Name: in Latitude: XX.XXXXXX Longitude: -XX.XXXXXXX Altitude: 46m Timezone: Date: Apr 3, 2011 7:04 PM Description: Address: Address2: City: State: Country: Postal Code: URL: Phone Number: Sent on the Sprint® Now Network from my BlackBerry®Name: in ,Latitude: XX.XXXXXX Longitude: -XX.XXXXXX Altitude: 46m Timezone: Date: Apr 3, 2011 7:04 PM Description: Address: Address2: City: State: Country: Postal Code: URL: Phone Number: Sent on the Sprint® Now Network from my BlackBerry® I am trying to break this statement into data that I can insert into a database table for weekly reports: Name: in Latitude: XX.XXXXXX Longitude: -XX.XXXXXXX Altitude: 46m Timezone: Date: Apr 3, 2011 7:04 PM Description: Address: Address2: City: State: Country: Postal Code: URL: Phone Number: Sent on the Sprint® Now Network from my BlackBerry® Link to comment https://forums.phpfreaks.com/topic/232720-breaking-down-statement/ Share on other sites More sharing options...
dcro2 Posted April 5, 2011 Share Posted April 5, 2011 Try something more like this: <?php $imap = imap_open("{abc.com:143}INBOX", "[email protected]", "**********"); $header = imap_header($imap, 1); $messages['body'] = imap_base64(imap_body($imap, 1)); $rmessage = ""; foreach($messages as $message){ $rmessage .= str_replace('Latitude:', ',Latitude: ', $message); } echo $rmessage; ?> You were concatenating together the string with the replacement to the original string. Link to comment https://forums.phpfreaks.com/topic/232720-breaking-down-statement/#findComment-1196997 Share on other sites More sharing options...
jmr3460 Posted April 5, 2011 Author Share Posted April 5, 2011 Hey thanks I got it working. When I looked at the source code of my output I noticed that there was line breaks. I replaced the line breaks with <br /> with n12br() then explode('<br />', $message);. I then count($message) and fun a for loop just to make sure I had it formated the right way. Next I will need to take my array and explode each array value into another array then insert into my database table. Thanks for the reply. I am going to bed now. Link to comment https://forums.phpfreaks.com/topic/232720-breaking-down-statement/#findComment-1197006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.