Jump to content

larka06

Members
  • Posts

    18
  • Joined

  • Last visited

larka06's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have some code working with arrays that I wrote but forgot what the "&" does to an array. I know the results and it works but I can not remember nor can I seem to find it anywhere. Probably not using the right search term. If some one can remind me It would be greatly appreciated.
  2. I just switch to a ubuntu server and it works so, it is not the code it is the operating system. Many Thanks to all of you
  3. I tried the script from gizmola and still get the same results, no open of file. vinny42 /home/******/pubic_html is my root directory. Apache owns it as well as the txt file I am trying to open. So are you saying I should move the file to /home/*****/public_html? This is where my webfiles are.
  4. I did not set home to 777. I did open home up for selinux. I have the program at a building stage so I know where I lose everything. All works well except for the opening of the file. It is for a small program that will take in orders add them up display all info and write to this flat file. Later, when I learn more, I will incorportate MySQL instead of this flat file. At present this will work for the fjist stages, that is if I can get it to open. Thanks for your time.
  5. The path is correct. I had it the second way but in desperation thought if I put it closer to the tree stem it might help. I just took the error suppression and I got nothing from ifopen(). I am running LAMP on CentOS 6.4 I opened up home directories on selinux There is just some small thing I am not seeing.
  6. I have been working on opening, writing to, and closing a text file. I have direct address to the file in my php. I have the directory and the text file world readable, writable, and excutionable, in short 777 in the whole path. I have also assigned the file name to apache:apache (user, group). I have tried my own machine name, no luck. Here is the code // open file for appending @ $fp = fopen("/home/orders/orders.txt", 'ab'); flock($fp, LOCK_EX); // LOCK THE FILE FOR WRITING if (!$fp) { echo "<p><strong> Your order could not be processed at this time. Please try again later.</strong></p></body></html>"; exit; } fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); // RELEASE WRITE LOCK fclose($fp); echo "<p>Order written.</p>"; My if is a boolean if true I write to the file. False I get not processed at this time. can anyone see something wrong? Thanks for any help
  7. Anybody heard of phpStorm? I am going to download it tomorrow night and try it.
  8. Sorry I was so thick I missed the whole point. No excuse just late and tired. I just changed the indentation and now it works. Many thank for both of you. I guess I needed the scolding to get my attention. As for Kicken being better I am sure he is. I am a real newbie trying to teach myself.
  9. I have no spaces after ether the beginning <<<END_TEXT or the botttom END_TEXT. I am sure that the problem is down in the lower part. as you can see I have marked the ones not recognized.
  10. To me the parse error suggests that there is a missing semi-colon or quotation something like that but I can not find a single case of not having matches. As for the regular Expressions I know nothing so I just copied out of the book. I have been over them several times and all seems right. I have comments where I know that the unreconition begins. Here is the parser statement then the code..... Parse error: syntax error, unexpected $end in sort_words_by_length.php on line 71. There is only 70 lines. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Sorting words in a block of text by length</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Geany 0.21" /> <link href="common.css" rel="stylesheet" type="text/css"/> </head> <body> <h1>Sorting words in a block of text by length</h1> <?php $myText = <<<END_TEXT But think not that this famous town has only harpooners, cannibals, and bumpkins to show her visitors. Not at all. Still New Bedford is a queer place. Had it not been for us whalemen, that tract of land would this day perhaps have been in as howling condition as the coast of Labrador. END_TEXT; echo "<h2>The text:</h2>"; echo "<div style=\"width: 30em; \">$myText</div>"; $myText = preg_replace("/[\,\.]/", "", $myText); $words = array_unique(preg_split("/[\n\r\t]+/",$myText)); usort($words, create_function('$a,$b', 'return strlen($a) - strlen($b);')); echo "<h2>The sorted words:</h2>"; echo "<div style\"width: 30em; \">"; foreach ($words as $word) { echo "$word "; } // Is teamed with above echo "</div>"; // Not sure about reconition. ?> //Not gettting reconized <p><a href="http://httpd.apache.org/"><img src="/icons/apache_pb2.gif" alt="[ Powered by Apache ]"/></a> </body> //Not gettting reconized </html> //Not gettting reconized. Line 70.
  11. Thank both of you. There is nothing above it but the opening <?php
  12. I have this error but can not see what is wrong. The parser says: PHP Parse error: syntax error, unexpected T_SL in sort_words_by_length.php on line 40. What is T_SL? below is the line it objects to followed by the whole text. <?php Line 40 -- $myText = <<<END_TEXT But think not that this famous town has only harpooners, cannibals, and bumpkins to show her visitors. Not at all. Still New Bedford is a queer place. Had it not been for us whalemen, that tract of land would this day perhaps have been in as howling condition as the coast of Labrador. END_TEXT; I have reread on heredocs and can not find anything wrong.
  13. The output below is what I get if I put the echo statement anywhere but in the while Loop. Just before the while Loop is entered both $i and $numLines have 5 for an answer. Therefore the while Loop runs once and only one line is Justified. I have tried to set $i to zero just before entering the loop still runs only once. I cannot get even one echo from inside the while Loop. <?php // The text to justify $myText = <<<END_TEXT But think not that this famous town has only harpooneers, cannibals, and bumpkins to show her visitors. Not at all. Still New Bedford is a queer place. Had it nt been for us whalemen, that tract of land would this day perhaps have been in howling condition as the coast of Labador. END_TEXT; $myText = str_replace("\r\n", "\n", $myText); $lineLength = 60; // desired line lenght $myTextJustified = " "; $numLines = substr_count($myText,"\n");$startOfLine = 0; echo $numLines; //Move through each line in turn for($i=0; $i < $numLines; $i++) $originalLineLength = strpos($myText, "\n", $startOfLine) - $startOfLine; $justifiedLine = substr($myText, $startOfLine, $originalLineLength); $justifiedLineLength = $originalLineLength; echo $numLines; echo $i // Keep adding spaces between words until the desired line length is reached while($i < $numLines -1 && $justifiedLineLength < $lineLength) { echo $i; for($j=0; $j< $justifiedLineLength; $j++){ if($justifiedLineLength < $lineLength && $justifiedLine[$j] == " ") { $justifiedLine =substr_replace( $justifiedLine, " ", $j, 0); $justifiedLineLength++; $j++; } } } // Add the justified line to the string and move to the start of the next line $myTextJustified .= "$justifiedLine\n"; $startOfLine += $originalLineLength + 1; ?> Here is the output. Justifying Lines of Text 55 Original text: But think not that this famous town has only harpooneers, cannibals, and bumpkins to show her visitors. Not at all. Still New Bedford is a queer place. Had it nt been for us whalemen, that tract of land would this day perhaps have been in howling condition as the coast of Labador. Justfied text: But think not that this famous town has only harpooneers, cannibals,
  14. Thanks for the advice on the php.ini file. I did as you say and will try it out now. As for me I am having more success now although, I was about to give up php. I like its' style alot like C.
  15. Thanks to both of you for your time. I put the php tags around the ending brace and it worked! Suprised yes because I had just taken them off but must of done something else because it works.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.