Help with dynamic text in Flash, plain text file & PHP

  • DartHead
  • Beginner
  • Beginner
  • User avatar
  • Posts: 56
  • Loc: NYC

Post 3+ Months Ago

Whew.

I've got a PHP form into which the user enters plain text data, which I then load into a plain text file. The text file is then read into a dynamic HTML text box in Flash. I've got everything working great, except there are huge gaps between the paragraphs of the output text that appear in Flash.

I imagine there is a function in PHP, like strip_tags(), which will format the text like this:

Item 1
Item 2
Item 3

What I'm getting is:

Item1

Item2

Item3

You can see the PHP code and text files here:
http://www.duke-music.com/new/

I don't think it's a problem with my Flash app, although I could be wrong. 'duke.html' contains the SWF. If you click on 'bio' you'll see what I mean. And 'entry.php' contains the PHP code.

I realize this may be vague. Ask me questions if I haven't explained myself well.

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • sevster
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 518

Post 3+ Months Ago

i'm not able to see the php code directly....permissions might be not available for me to do that....all i see is the form to edit text.

if you can paste the php code here, that will be helpful.

thanks,

-sevster-
  • TsX
  • Graduate
  • Graduate
  • User avatar
  • Posts: 167

Post 3+ Months Ago

If I had to take a guess at it, I'd say it has something to do with your flash, or something to do with passing multiline variables into flash.

And maybe you want to try making the text render as html. and use <br> tags. I've never used the feature myself, but play around a bit, I'm sure you'll figure something out.
  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

the <br> suggestion above is a good one, for sure...

as i'm not really sure how you're loading it up, there's three direction's i'll point you in:

1) some servers interperet the text differently, so, for instance, when i view dynamic text on my machine at home, it shows double spacing, but when i view it from a remote linux server, the spacing is right...

2) http://www.actionscript.org/forums/arch ... 45465.html
3) http://www.actionscript.org/forums/arch ... 36615.html

hope something here helps...

peace out
  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

the <br> suggestion above is a good one, for sure...

as i'm not really sure how you're loading it up, there's three direction's i'll point you in:

1) some servers interperet the text differently, so, for instance, when i view dynamic text on my machine at home, it shows double spacing, but when i view it from a remote linux server, the spacing is right...

2) http://www.actionscript.org/forums/arch ... 45465.html
3) http://www.actionscript.org/forums/arch ... 36615.html

hope something here helps...

peace out
  • DartHead
  • Beginner
  • Beginner
  • User avatar
  • Posts: 56
  • Loc: NYC

Post 3+ Months Ago

Thanks guys!

roarmeow, your second item was right on. Thanks for finding it.

This is the answer:

Code: [ Select ]
$str=str_replace("\r","",$str);


So simple! I tried replacing the "\n", but I forgot that Windows adds a "\r", as well.

In case anyone's interested, here is the complete code. (Sorry, sevster, I thought you could download the PHP file and open it in a text editor.) I realize this is a Flash forum, but if anyone has suggestions for more elegant coding, I'd love to hear them. I've been coding PHP for less than a month.

Code: [ Select ]
<HTML>
<HEAD>
<TITLE>Form Entry</TITLE>
</HEAD>
<BODY><FONT face="verdana" color="#333333" size="-5">
<TABLE cellpadding="5">
<FORM action="<?php echo $_SERVER['PHP_SELF'];?>" method = "POST">
<TR>
    <TD align="right" valign="top">Enter text:<br />
  (WARNING:crawltext.txt &amp; biotext.txt<br />
  will erase existing text!)
    <TD><TEXTAREA name="content" rows="10" cols="50"></TEXTAREA>
</TR>
<TR>
    <TD align="right">Select form to edit:
    <TD><SELECT name="file">
    <OPTION>crawltext.txt</OPTION>
    <OPTION>biotext.txt</OPTION>
    <OPTION>tourstext.txt</OPTION>
    <OPTION>presstext.txt</OPTION>
    </SELECT>
</TR>
<TR align="right">
    <TD colspan="2"><INPUT type="submit" value="Send it!"><input type="reset" value="Reset" src="_self" />
</TR>
</FORM>
</TABLE>
<?PHP
function replace(&$str){
    $find = array("Duke","DUKE","duke","<font color = '#FFB907'><b>DUKE</b></font>");
    $replace = "<font color = '#FFB907'><b>DUKE</b></font>";
    $str = str_replace($find,$replace,$str);
    $str=str_replace("\r","",$str);
}
if(isset($_POST['content'])||isset($_POST['file'])){
  $content = $_POST['content'];
  $file = $_POST['file'];
}else{
  $content = '';
  $file = '';
  $data = '';
  $mode = '';
  $fh = '';
}
switch ($file) {
    case "crawltext.txt" :
        strip_tags($content);
        $data = "crawltext=".$content;
        break;
    case "biotext.txt" :
        $data = "biotext=".$content;
        replace($data);
        break;
    case "tourstext.txt" :
        $data = file_get_contents($file) or die("Couldn't read ".$file);
        $data = preg_replace('{tourstext=}','',$data);
        $data = "tourstext=".$content."<!--ENTRY BEGINS HERE--><br /><br />".$data."<!--ENTRY ENDS HERE-->";
        replace($data);
        break;
    case "presstext.txt" :
        $data = file_get_contents($file) or die("Couldn't read ".$file);
        $data = preg_replace('{presstext=}','',$data);
        $data = "presstext=".$content."<!--ENTRY BEGINS HERE--><br /><br />".$data."<!--ENTRY ENDS HERE-->";
        replace($data);
        break;
}
if($file!=null){
    $fp = fopen($file, 'w');
    if(!$fp) {
        trigger_error('Cannot open file.', E_USER_ERROR);
        return;
    }
    fputs($fp, stripslashes($data));
    fclose($fp);

$readfile = file_get_contents($file);
echo "File updated:<P>".$readfile;
}
?>
</BODY></FONT>
</HTML>
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Form Entry</TITLE>
  4. </HEAD>
  5. <BODY><FONT face="verdana" color="#333333" size="-5">
  6. <TABLE cellpadding="5">
  7. <FORM action="<?php echo $_SERVER['PHP_SELF'];?>" method = "POST">
  8. <TR>
  9.     <TD align="right" valign="top">Enter text:<br />
  10.   (WARNING:crawltext.txt &amp; biotext.txt<br />
  11.   will erase existing text!)
  12.     <TD><TEXTAREA name="content" rows="10" cols="50"></TEXTAREA>
  13. </TR>
  14. <TR>
  15.     <TD align="right">Select form to edit:
  16.     <TD><SELECT name="file">
  17.     <OPTION>crawltext.txt</OPTION>
  18.     <OPTION>biotext.txt</OPTION>
  19.     <OPTION>tourstext.txt</OPTION>
  20.     <OPTION>presstext.txt</OPTION>
  21.     </SELECT>
  22. </TR>
  23. <TR align="right">
  24.     <TD colspan="2"><INPUT type="submit" value="Send it!"><input type="reset" value="Reset" src="_self" />
  25. </TR>
  26. </FORM>
  27. </TABLE>
  28. <?PHP
  29. function replace(&$str){
  30.     $find = array("Duke","DUKE","duke","<font color = '#FFB907'><b>DUKE</b></font>");
  31.     $replace = "<font color = '#FFB907'><b>DUKE</b></font>";
  32.     $str = str_replace($find,$replace,$str);
  33.     $str=str_replace("\r","",$str);
  34. }
  35. if(isset($_POST['content'])||isset($_POST['file'])){
  36.   $content = $_POST['content'];
  37.   $file = $_POST['file'];
  38. }else{
  39.   $content = '';
  40.   $file = '';
  41.   $data = '';
  42.   $mode = '';
  43.   $fh = '';
  44. }
  45. switch ($file) {
  46.     case "crawltext.txt" :
  47.         strip_tags($content);
  48.         $data = "crawltext=".$content;
  49.         break;
  50.     case "biotext.txt" :
  51.         $data = "biotext=".$content;
  52.         replace($data);
  53.         break;
  54.     case "tourstext.txt" :
  55.         $data = file_get_contents($file) or die("Couldn't read ".$file);
  56.         $data = preg_replace('{tourstext=}','',$data);
  57.         $data = "tourstext=".$content."<!--ENTRY BEGINS HERE--><br /><br />".$data."<!--ENTRY ENDS HERE-->";
  58.         replace($data);
  59.         break;
  60.     case "presstext.txt" :
  61.         $data = file_get_contents($file) or die("Couldn't read ".$file);
  62.         $data = preg_replace('{presstext=}','',$data);
  63.         $data = "presstext=".$content."<!--ENTRY BEGINS HERE--><br /><br />".$data."<!--ENTRY ENDS HERE-->";
  64.         replace($data);
  65.         break;
  66. }
  67. if($file!=null){
  68.     $fp = fopen($file, 'w');
  69.     if(!$fp) {
  70.         trigger_error('Cannot open file.', E_USER_ERROR);
  71.         return;
  72.     }
  73.     fputs($fp, stripslashes($data));
  74.     fclose($fp);
  75. $readfile = file_get_contents($file);
  76. echo "File updated:<P>".$readfile;
  77. }
  78. ?>
  79. </BODY></FONT>
  80. </HTML>

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.