Jump to content

breaking down statement


jmr3460

Recommended Posts

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

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.

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.

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.