Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by iwato

  1. iwato

    Regular Expression

    I have made some progress. The following code will extract each of the words without the quotations as separate words. One need merely change the N to a number. For example, \3 yields kiwis.Text: "apples", "oranges, kiwis, mangos", "penguins"Find: "([\w]+)[", ]+([\w]+)[", ]+([\w]+)[", ]+([\w]+)[", ]+([\w]+)"Replace: \NWhat it does not do is1) Do the same for any number of delimited pairs.2) Render faithfully what is inside each pair of delimiters.Roddy
  2. iwato

    Regular Expression

    Alone this does not resolve the problem, but it does add a new vantage point. Find: "([^"]+)" Replace: \1String: "apples", "oranges, kiwis, mangos", "penguins"Result: apples, oranges, kiwis, mangos, penguinsThis is nice insofar as it goes, but it does not yet permit me to replace the entire string with only apples, only oranges, kiwis, mangos, or even only penquins. It claims to have discovered three matches, but only \1 yields anything very useful. \2 and \3 result only in empty commas.I will play with it a little more, and let you know the result.Thanks for your good effort.
  3. iwato

    Migrating to PCRE

    No, no! If you were using the character a only as an example, it is the wrong character to be used for that. According to the TextWrangler manual \a is a special character for the so-called hexidecimal BEL or alarm character: \x07.By way of further suggestion, why not substitute with hexidecimal characters where you are having trouble. For example, you could rewrite $ as \x24. Parentheses might also work as Justsomeguy suggested.Roddy
  4. iwato

    Migrating to PCRE

    I am surprised that this works, as it would appear that the first backward slash in the pattern \\\$ escapes the second, and that the third escapes the $ metacharacter that would otherwise indicate the end of the line.Roddy
  5. iwato

    Regular Expression

    PROBLEM: Consider the following sequence of an unknown number of delimited patterns. "oranges", "apples", "bananas, grapes, and kiwi", . . . , "other fruit"Write a Find command using GREP (Regular Expressions) that isolates the contents of each pair of delimiters, but does not include the delimiters. Write this pattern in such a way that one or more of the resulting aubpatterns can be selected at will and used to replace the content of the original sequence without the delimiters. The number of kinds of fruit in any given subpattern must be retained. What I thought would be a fairly simple task has proven very challenging.Roddy
  6. iwato

    Regular Expression

    OK. Now to question three, and my understanding should be complete.QUESTION THREE: Does the $ symbol after the second sub-pattern indicate the end of the sub-pattern or the end of the line from which the matched sub-pattern is drawn? I ask this question because the replace operation yields very different results when the $ symbol is omitted. In effect, it appears, as if the end-of-line marker were included in the second sub-pattern when the $ is omitted.Roddy
  7. iwato

    Regular Expression

    FOLLOW-UP QUESTIONS:Please review the following statements and state whether each is true or false. If it is false, please explain why?1) The space between the two sets of parentheses in the Find expression is neither arbitrary nor convenient; rather, it is necessary, and would lead to a different result, if there were, say three spaces, instead of one.2) Although the dot refers to any character except line breaks, it does not refer to characters that create white space.RoddyP.S. I got this example from TextWrangler user's manual and am now able to recommend TextWrangler to others who do a lot of work with highly structured data and code. Thank you for turning me on to it.
  8. iwato

    Regular Expression

    QUESTION: The following set of Find and Replace commands are used to perform the below transformation. What I do not understand is how these two commands achieve their goal. Could someone provide a clear explanation as to how the transformation takes place?What I understand is that the \2 refers to the second sub-pattern, and \1 refers to the second. I also understand that the first sub-pattern refers to the entirety of one line excepting the end-of-line marker. What I do not understand is how the second sub-pattern is used to obtain the transformation.By the way, the transformation has been tested and clearly works.REGULAR EXPRESSIONS:The set of find and replace commands used to achieve the task are the following:FIND: (.+) ([^ ]+)$REPLACE: \2, \1 THE DATA:Consider briefly the following set of data:Junior X. PotterJill SafaiDylan Schuyler GoodeWalter WangAssume that a line break appears at the end of each line except for the last line.THE TRANSFORMED DATA:The goal is to produce the following reordering of each name.Potter, Junior X.Safai, JillGoode, Dylan SchuylerWang, WalterOnce again, it works.Roddy
  9. It is time to wrangle. Many thanks!Roddy
  10. Are you familiar with something called auto_detect_line_endings? Would it not be appropriate in this context?Roddy
  11. The problem with performing a replace is that I do not know what I would be replacing, as I cannot see it.Roddy
  12. I finally received a response from MAMP Pro. Perhaps it was because I sent an email in German to the support team's German address and asked for a telephone number. They believe that the problem had to do with blank characters. They still have responded to my query about permissions . . . .Are there PHP functions that could eliminate hidden characters in a document?Roddy
  13. Yes and no. I have just deleted and retyped the entire code in Dreamweaver. It ran.Needless to say, I am very frustrated by the outcome of these events. Why? This means that Dreamweaver permits hidden characters in its code section. And to think, that I copied the code into TextEdit from the PHP website, reformatted it as text, and saved it before copying it into Dreamweaver. I am very disheartened.Roddy
  14. Examine the entire post -- both the CODE and QUOTE. The latter contains the source code for the randomly generated file.Roddy
  15. I have already provided that information in Post #16Roddy
  16. In a previous experiment and entry to this thread I explained that is_writable(), when run by itself, produces a 1. The file practice.txt is writable.Please find copies of both the php and text files at the following two URLs: fwrite.php and practice.txt, respectively.By the way, I have now reinstalled by system folder as well as Dreamweaver and the entire suite of Adobe CS3's shared components. The only piece of software in play that I have still have yet to reinstall is MAMP Pro.Roddy
  17. Those three sets of code were run in order to test whether the file practice.txt would be recognized under different environments. It was recognized in only one of the three environments in which it was tested.The code that I am currently running is: <?php $filename = 'practice.txt'; $somecontent = 'Add this text to the file\n'; if (is_writable($filename)) { $handle = fopen($filename, 'a'); if (!$handle) { echo 'Cannot open file ($filename)'; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo 'Cannot write to file ($filename)'; exit; } echo 'Success, wrote ($somecontent) to file ($filename)'; fclose($handle); } else { echo 'The file ($filename) is not writable'; } ?> TMP4043XKHRZ.php is generated by Dreamweaver. It is automatically produced when I test my PHP document with Safari. The name is randomly assigned each time a test is run. Please find below the source view of the file named TMP4043XKHRZ.php.
  18. Good morning, everyone! In post three I posted three sets of code. Each was run independently of the other and provided the results indicated. The file called practice.txt is just an ordinary text file created with TextEdit and saved into my Dreamweaver file folder. The folder has been updated several times.Also, there is nothing unusual about my character fonts. They are standard UTF-8 found on all Apple Computers.Roddy
  19. I am beginning to believe that the error is with the MAMP Pro or Dreamweaver. MAMP Pro is not responding to my support requests, and recently I have had trouble uploading to one of my websites using Dreamweaver. It is very frustrating when people with many years of experience can find no error in my code, and I keep receiving the same error message despite numerous modifications.Roddy
  20. The error message is the same as before and line 37 corresponds to the following statement: if (is_writable($filename)) {ERROR MESSAGE: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Applications/MAMP/htdocs/php-practice/functions/filesystem/fwrite/TMP4043XKHRZ.php on line 37Roddy
  21. OK. So, I tried the following. No change in the error message. <?php $filename = 'practice.txt'; $somecontent = 'Add this text to the file\n'; if (is_writable($filename)) { $handle = fopen($filename, 'a'); if (!$handle) { echo 'Cannot open file ($filename)'; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo 'Cannot write to file ($filename)'; exit; } echo 'Success, wrote ($somecontent) to file ($filename)'; fclose($handle); } else { echo 'The file ($filename) is not writable'; } ?> What does work is the following: <?php $filename = 'practice.txt'; echo is_writable($filename);?> The output is 1.Roddy
  22. Actually, I am not surprised that you were unable to reproduce the error, because I do not believe that the error has anything to do with the code per se. Also, please read carefully what I wrote in my last entry; each of the three sets of code displayed was run separately. In separate trials I substituted the PHP code in the last set with the PHP code from the first and second sets, respectively. I do not understand this statement. Perhaps you could provide an example of what you mean and show how it may be relevant to each of the three sets of code to which you meant it to apply.Roddy
  23. Based upon what you have written I can well appreciate your desire to see the entire error message, but consider the two separately run blocks of code first. The first produces the desired number 1. The second produces the same error message that I have already provided and am providing again in full.Line 37 by the way is the line just after the statement: echo $file_exists($filename);<?php echo $file_exist('practice.txt');?> and <?php $filename = 'practice.txt'; echo $file_exist($filename);?> Error Message: // Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Applications/MAMP/htdocs/php-practice/functions/filesystem/fwrite/TMPL10XJMP4.php on line 37 I found this very helpful. Slowly, but surely, I am learning how to use the PHP Manual. The code for the entire PHP webpage is provided below -- a snapshot of how I am studying PHP, one function and group of functions at a time.<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>PHP Filesystem - The fwrite( ) Function</title><style type="text/css"><!--body { font: 100% Verdana, Arial, Helvetica, sans-serif; background: #666666; margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */ padding: 0; text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */ color: #000000;}.oneColElsCtr #container { width: 46em; background: #FFFFFF; margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */ border: 1px solid #000000; text-align: left; /* this overrides the text-align: center on the body element. */}.oneColElsCtr #mainContent { padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */}--></style></head><body class="oneColElsCtr"><div id="container"> <div id="mainContent"> <h1>PHP Filesystem - The fwrite( ) Function</h1> <?php $filename = 'practice.txt'; $somecontent = "Add this text to the file\n"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> <p></p> <!-- end #mainContent --></div><!-- end #container --></div></body></html>
  24. QUESTION ONE: What is a T_CONSTANT_ENCAPSED_STRING?QUESTION TWO: Why might it appear as a parsing error when the following block of code is run?QUESTION THREE: How does one go about finding a definition of the above constant, and for the future other such constants?ERROR MESSAGE: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in . . . .BACKGROUND1) The file "practice.txt" and the file containing the PHP code provided below coexist in the same folder.2) The command line to which the error message points has little or no relevance to the statement found in the line. I know this because I have entered other statements in the same line. 3) The following block of code is the only PHP code in the entire php file. <?php $filename = "practice.txt"; $somecontent = "Add this text to the file\n"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Roddy
  25. iwato

    The sleep( ) Function

    As always, thank you for responding, but I am still unsure and wish to be clear about my illusions. I was once taught that you can appear smart in the moment, not ask the question, and be dumb for a life-time, or appear dumb in the moment, ask the question, and be smart for a life-time. As I have usually found the latter alternative the wiser, please tell me, if the following statements are correct:(True or False) A file buffer is a buffer that is created when a file is opened as a resource using the fopen( ) function. Functions such as the fflush( ) and stream_set_write_buffer( ) functions can only flush the buffers of files that are open resources.(True or False) Output buffers and file buffers are separate entities. You can flush both or either, but flushing either does not flush the other.If false, please explain why.Roddy
  • Create New...