yep. I recommend SESSION vars myself, though you have to be careful, as some people dont accept the proper cookies... so make sure to use a session ID if it's important.
Kllrnohj & Alex10819: I was just talking about variable scope within one execution cycle (page load). Of course variables don't carry over between pageloads; you have to reinit the MySQL connection every time a page is loaded, lafferjm.
KermMartian wrote:
Kllrnohj & Alex10819: I was just talking about variable scope within one execution cycle (page load). Of course variables don't carry over between pageloads; you have to reinit the MySQL connection every time a page is loaded, lafferjm.


yeah, but I was making sure HE knew that distinction, because it wasn't sounding like it Razz
Kllrnohj wrote:
KermMartian wrote:
Kllrnohj & Alex10819: I was just talking about variable scope within one execution cycle (page load). Of course variables don't carry over between pageloads; you have to reinit the MySQL connection every time a page is loaded, lafferjm.


yeah, but I was making sure HE knew that distinction, because it wasn't sounding like it Razz
Ah, gotcha. I would hope that you know that I know that by now. Very Happy
Is there a function or easy way in php to read a textarea line by line? I have searched for solutions but there doesn't seem to be one. If there isn't an easy way to do it i have an idea on what i need to do to get it done.
You'd probably want to go with split(), specifically split("\n",$string);.
alright i will try that out, i was trying to make it work with explode as well. You also posted before i could edit and add source so here is the source for what i was trying to do:


Code:

;noteapp.php
<html>
<head>
<title>Note Writer</title>
</head>
<body>
<form action="display.php" method="post">
<textarea rows="30" cols="75" name="note"></textarea>
<input type="submit" value="Get string" />
</form>
</body>
</html>



Code:

;display.php
<html>
<head>
<title>Note Writer</title>
</head>
<body>
<?php
$lines = explode("\n",$_POST['note']);
foreach($lines as $temp) {
  echo $temp."\n";
}
?>
</body>
</html>
explode() is just an alias for split() to keep perl sorta-compatibility and make it more intuitive for perl programmers.
I tried your suggestion and it still didn't work. I need to break the line at 75 characters which is why the textarea is 75 columns long. To see what the thing is actually doing here is where i am hosting it. http://fearlessu.freehostia.com/noteapp.php
Hmm, I think I understand what you're trying to do now. Check it:


Code:
<?php
$message = strip_slashes($_POST['note']);
$linestart = 0;
$curchar = 0;
$lastspace = 0;
$outlines = array();
while($curchar < strlen($message) {
     while(($curchar-$linestart <= 75) && ($curchar<=strlen($message))) {
          if (substr($message,$curchar,1) == " ") $lastspace = $curchar;
          $curchar++;
     }
     if ($curchar >= strlen($message)) $lastspace = $curchar;
     $outlines[] = substr($message,$linestart,$lastspace-$linestart+1);
     $linestart = $curchar = $lastspace+1;
}
print_r($outlines);
?>
Thanks a lot for that snippet of code it worked exactly like i wanted it to. I was about to do a solution similar to that but it would have been a lot more messy. And at the bottom of the page i will be sure to add a thanks in there to you. Very Happy
lafferjm wrote:
Thanks a lot for that snippet of code it worked exactly like i wanted it to. I was about to do a solution similar to that but it would have been a lot more messy. And at the bottom of the page i will be sure to add a thanks in there to you. Very Happy
Wow, that actually worked correctly without any testing? Shock I'm stunned, that may be the first time that's happened. Very Happy You're most welcome - you should try to look through my code and see what it's doing.
I know what it does, it does the same thing i was about to do if a function didn't exist to do it.
lafferjm wrote:
I know what it does, it does the same thing i was about to do if a function didn't exist to do it.
Pwnful, glad to hear it. Good luck with this project, then, and keep us posted on progress.
Will do. And seeing as you don't know what it is for yet let me explain it a bit first. I am playing a MUD called dragonstone. And on there a lot of people role play, but the majority of the role playing comes in the form of notes. The note editor on the game sucks and the only other way to do it is to type a note in a text editor. After typing it into the text editor you have to hit return at the end of each line and then copy and paste each one. This can be a pain so that is where my app comes in.

And as far as updates i have added two foreach loops. One to display the text in paragraph form and the other to write the line that needs to be copied and pasted into the mud client. Now i just have to write one more update that will allow for color then it will be pretty much done.
Even better would be to figure out their API and drop some AJAX together that will let your application communicate directly with their servers and act as a standalone chat client.
To advanced for me yet. And to add colors im going to use the str_replace() function. After i add it in it should be done then i can sit around thinking of something else to work on.
lafferjm wrote:
To advanced for me yet. And to add colors im going to use the str_replace() function. After i add it in it should be done then i can sit around thinking of something else to work on.
Str_replace sounds fine for this application. Also, if you don't know regex for preg_match() and preg_replace(), you really should learn it. Regular expressions are amazingly powerful.
I have never heard of those two functions so i will go ahead and look them up.
I have researched them and they are pretty good so i decided to try and use them. As it turns out i think i am using them wrong. I need to replace strings that look like &Y with <font color="yellow"> but it doesn't seem to replace it. Am i doing anything wrong.
Code:
<html>
<head>
<title>Note Writer</title>
</head>
<body bgcolor="black">
<?php
$message = stripslashes($_POST['note']);
$linestart = 0;
$curchar = 0;
$lastspace = 0;
$outlines = array();
while($curchar < strlen($message)) {
     while(($curchar-$linestart <= 75) && ($curchar<=strlen($message))) {
          if (substr($message,$curchar,1) == " ") $lastspace = $curchar;
          $curchar++;
     }
     if ($curchar >= strlen($message)) $lastspace = $curchar;
     $outlines[] = substr($message,$linestart,$lastspace-$linestart+1);
     $linestart = $curchar = $lastspace+1;
}

$outlinescpy = $outlines;

$rep[0] = "/&r/";
$rep[1] = "/&b/";
$rep[2] = "/&Y/";
$rep[3] = "/&c/";
$rep[4] = "/&R/";
$rep[5] = "/&B/";
$rep[6] = "/&O/";
$rep[7] = "/&w/";
$rep[8] = "/&g/";
$rep[9] = "/&c/";
$rep[10] = "/&p/";
$rep[11] = "/&z/";
$rep[12] = "/&G/";
$rep[13] = "/&W/";
$rep[14] = "/&P/";

$rep1[0] = "<font color='#8b0000'>";
$rep1[1] = "<font color='#00008b'>";
$rep1[2] = "<font color='#ffff00'>";
$rep1[3] = "<font color='#008b8b'>";
$rep1[4] = "<font color='#ff0000'>";
$rep1[5] = "<font color='#add8e6'>";
$rep1[6] = "<font color='#ffa500'>";
$rep1[7] = "<font color='#d3d3d3'>";
$rep1[8] = "<font color='#006400'>";
$rep1[9] = "<font color='#e0ffff'>";
$rep1[10] = "<font color='#800080'>";
$rep1[11] = "<font color='#a9a9a9'>";
$rep1[12] = "<font color='#90ee90'>";
$rep1[13] = "<font color='#ffffff'>";
$rep1[14] = "<font color='#9370db'>";

print "<font color='lightgreen'>";

foreach($outlines as $temp) {
     preg_replace($rep, $rep1, $temp);   
     echo $temp."<br />";
}
$a = 1;
foreach ($outlinescpy as $temp1) {
     if($a == 1) {
         $msg = $temp1.";";
     } else {
         $msg = $msg.$temp1.";";
     }
     $a = $a + 1;
}
print "<br />"."<br />"."<br />";
print "<b>Copy and paste the following line into your client to post note</b>";
print "<br />";
echo $msg;
?>
</body>
</html>


If i am doing something wrong can you please point me in the right direction and not fix it for me, i want to try to figure it out for myself.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
» View previous topic :: View next topic  
Page 7 of 8
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement