Hi Everyone,

Merry Christmas!

I need some input. I have a form that users input their comments into a database I store it in a longtext field.

Now I am getting it out and need to convert their records to an excel file and everything works great, except, if they put a return in the field. It stores it in the longtext, and when I read it out and write the csv, it reads as a new line and starts a new record.

Example:
The entered :
Test
1
2
3

I want to change it to:

Test 1 2 3 (in my CSV file)

I run all my records thru an HTML strip function to remove as much 'junk' (ie href, and code as possible) but I tried to remove the line feeds as such and it did not work.

function htmldeletechars( $string )
    {
        $string = str_replace ( '<br>', '', $string );
        $string = str_replace ( '<p></p>', '', $string );
        $string = str_replace ( '\n\r', '', $string );

    return $string;
}

I appreciate the help in advance,

Regards,
Don

    '\n\r' should be "\r\n", or perhaps "\r" and "\n" separately.

      Thanks for pointing that out.

      I did what you suggested.

      Just in case, I am off base somewhere else, here is my function in it's entirety.

      function htmldeletechars( $string )
          {
              $string = str_replace ( "http", "", $string );
              $string = str_replace ( ":", "", $string );
              $string = str_replace ( "//;", "", $string );
              $string = str_replace ( "<", "", $string );
              $string = str_replace ( ">", "", $string );
              $string = str_replace ( "com", "", $string );
              $string = str_replace ( "org", "", $string );
              $string = str_replace ( "net", "", $string );
              $string = str_replace ( "\//", "", $string );
              $string = str_replace ( "/", "", $string );
              $string = str_replace ( "www", "", $string );
              $string = str_replace ( "href", "", $string );
              $string = str_replace ( "htm", "", $string );
              $string = str_replace ( "html", "", $string );
              $string = str_replace ( "php", "", $string );
              $string = str_replace ( "asp", "", $string );
              $string = str_replace ( "&", "", $string );
              $string = str_replace ( "%", "", $string );
              $string = str_replace ( "@", "", $string );
              $string = str_replace ( "\n", "", $string );
              $string = str_replace ( "\r", "", $string );
      
          return $string;
      }
      
      

      Thanks for the help,
      Don

        Eh, that seems like too much filtering. For example, suppose a user comments:

        Gasp! I found an organisation on the Internet that sells computers with a 100% discount!

        It will be filtered to:

        G! I found an anisation on the Inter that sells puters with a 100 discount!

          Yes, you are right. But in the same sense, I have the spammers put up ..

          <a href="blah blah blah">Vialas or whatever garbage nobody wants to hear about.</a>

          and in the excel file, it turns it into

          fa fg whsdver <--- and removed the html links, and the ability of someone accidentally clicking on this in excel and going to the link when they meant to edit it.

          Does that make sense?

          I get your point, but I need some way to stop the loser spammers by shutting off their links and email address's in the excel file.

          I am TOTALLY open to alternate ways. If I could remove the HTML links 'before' they were stored in MySQL that would solve the accidental link issues in the exported file.

          Thanks,

          Don

            You could just use [man]strip_tags/man, or even better: craft regular expression to remove links.

              I found this function (for stripping the HTML links, doesn't remove the link breaks, but solves the SPAM issue).

              function htmldeletechars($string){
              		$search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
              					   '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
              					   '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
              					   '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
              		);
              		$text = preg_replace($search, '', $string);
              		return $text;
              		}
              

              Worked well for me.

              Thanks, now if I could remove the line breaks, I could resolve this thread.

              Don

                Well, reuse the portion of your earlier code that allowed you to remove link breaks.

                  As usual, you are correct. Here is the remaining code for anyone who needs it.

                  function htmlstripline( $string )
                      { 
                          $string = str_replace ( "\n", " ", $string );
                          $string = str_replace ( "\r", " ", $string ); 
                          return $string;
                      } 
                  
                  $var = htmlstripline($var);
                  

                  Thanks,

                  Thread Resolved.

                  Merry Christmas!

                  Don

                    Write a Reply...