Jump to content


Photo

Problem with flat file being read by Flash


  • Please log in to reply
7 replies to this topic

#1 m00gzilla

m00gzilla
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2006 - 03:01 AM

Hi - my first post here

I have a flat file that gets created in PHP and read in Flash. The problem I am having is when Flash shows the text from the flat file, it bring's with it escape codes (\n) and html nbsp codes.

Is there something in the php script I need to add to keep it from doing this?? Originally when I was testing from the Flash .swf file, it read the text fine without any extra characters. So, i'm assuming now it's coming from the PHP side.

Any help would be great!
Thanks!


#2 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 21 September 2006 - 03:08 AM

I don't know how you are getting your text to the php but this example will change '/n' to ' ' in the input from a $_POST form submit

$texttopass = str_replace("\n"," ",$_POST['textfromphp']);

put a line like this after your input is recieved and before your text file is written to

#3 m00gzilla

m00gzilla
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2006 - 02:20 PM

Thanks Trillion. That helped clean up some of it. Now I am still getting the escape character whenever quotes are used.
example:  This is what it shows if I use \"quotes\".



#4 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 21 September 2006 - 03:00 PM

instead of str_replace try ereg_replace("\s+", " ", $string);

That should take any tabs, newlines and white space and convert it to a single space

#5 m00gzilla

m00gzilla
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2006 - 04:13 PM

instead of str_replace try ereg_replace("\s+", " ", $string);

That should take any tabs, newlines and white space and convert it to a single space


ok, tried that. It removed all the 's' characters from the string and replaced them with blanks.

#6 m00gzilla

m00gzilla
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 September 2006 - 11:14 AM

ok, here is my php code

<?php

if (isset($_POST['Description'])) // If form was submitted with a message
{
  $File = 'news.txt'; // Set filename

  $Handle = fopen($File, 'w'); // If file does not exist, create it
  
  $rep = str_replace("\n"," ",$_POST['Description']);
  $Write = fwrite($Handle, $rep); // Write the new entry to the end
  $Close = fclose($Handle); // Close the file
}

?>

I'm still having the issue of anytime a quote is used I get /" /" instead of " "




#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 September 2006 - 11:26 AM

Use stripslashes in that case. Your serverprobably has a setting called magic_quotes enabled which escapes quotes automatically, thus you get \" instead of ". stripslashes will unescape the escaped characters.

#8 m00gzilla

m00gzilla
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 September 2006 - 12:49 PM

Thanks!!!

Worked perfectly...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users