I am extracting data from Salesforce.com via their API using PHP. I can store the data in MySQL without an issue when it comes to any field type except multi-line.

In Salesforce, the field is like a notes section and entries are stored with line breaks, chr(13), chr(10), etc..

When I insert it into MySQL, it concatenates it into one long string.

If I query this field from MySQL I cannot get it to format like it is in Salesforce.

There is a discussion on this on my site (sorry for the external link, but I thought it would explain it better) > http://www.mikesimonds.com/salesforce-php-tutorials/47-salesforce-php-mysql-database-replication-tool-6.html

Some friends have said that I should use base64_encode to insert and base64_decode , but I have tried it.

Are there any tips or tricks that I am missing here, I would REALLY appreciate any help.

Thanks in Advance

~Mike

    if you do a dump of the db in phpmyadmin and open the file in notepad, do you get the line breaks?

      Then either the api is not returning line breaks, or your striping them when you insert them in to the db, you want to find out which firsts.

      retrieve a field via the api, don't put it in to the db just echo it to the browser wrapped in html pre tags (or view source) that should accurately tell you if the line breaks exist.

        agreed you would need to contact them.

        Don't suppose you want each sentence to be a new line? if so an easy but silly work around would be to replace each full stop with a line-break and full stop.

          How would you do that sir, sorry to ask!!

            entries are stored with line breaks, chr(13), chr(10), etc..

            Maybe you can use [man]nl2br[/man] ( Newline to Break )
            This function is useful when displaying text in HTML-pages.
            Will add <br /> for chr(10)= '\n' ( or chr(13)+chr(10) \r\n )

            You can keep your entries as they are in MySQL,
            but you use nl2br() to add <br />
            when you want to display your text in pages.

            Sometimes we also may want to use [man]htmlspecialchars[/man] before displaying.
            htmlspecialchars() should be applied to text before nl2br() otherwise <br /> will not work.

            <?php
            
            $text = "this is first line\r\n this is second";
            
            echo $text;
            echo '<hr />';
            echo nl2br($text);
            
            exit();
            
            //when using both nl2br and htmlspecialchars
            echo nl2br( htmlspecialchars($text) );
            
            ?>

              Right but if they are being stored in a text field or string in MySQL, I do no know where the line breaks are?

              maybe explode on Periods?

              ~Mike

                halojoy, i think we have established that they are being striped out unfortunately.

                msimonds,

                $out=str_replace('.','.<br>',$in);

                or

                $out=str_replace('.','.\n',$in);

                then nl2br()

                we are simply replacing the "." with a line-break (html or asci) and putting the "." back in

                  msimonds;10948631 wrote:

                  Right but if they are being stored in a text field or string in MySQL, I do no know where the line breaks are?

                  maybe explode on Periods?

                  ~Mike

                  they are not being stored at all, they are being 'lost', that's the problem

                    okay I just took off my stupid cap, sorry about that, got it

                    Thanks all for the help, I think I can manage it from here. You are all great as always on this site

                    ~mike

                      Write a Reply...