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", "mark@abc.com", "**********");
  $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
Share on other sites

Try something more like this:

<?php
$imap = imap_open("{abc.com:143}INBOX", "mark@abc.com", "**********");
  $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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.