Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About justinh

  • Rank
  1. justinh

    quotes in POST but not in variable

    I have a bit of a mystery with quotes in variables. I'm writing an application that takes a text string from a page from via POST, and I was concerned about dealing with single or double quotes. I know that if you use single to wrap the content, then there is no issue processing double: $myvar = 'I say "hello" world'; // I say "hello" world And if you use double to wrap the content, then there is no issue processing single: $myvar = "I say don't do that"; // I say don't do that If you use the same quote inside and outside w/o escaping the non-wrapping quotes, PHP will throw an error. Example: $myvar = "I say "hello" world"; // => Parse error So, I expected my POST values to give me errors if I didn't escape or convert to HTML codes, but I thought how can I do either to prevent an error w/o first incurring the error while extracting the POST data? I just tried using both quotes in my strings and everything works fine. $desc1 = ($_POST["desc1"]); echo $desc1; // this is double "test" and single 'test' string Even if I quote the variable in the echo it works. Why do I not get an error when going thru the POST? Justin
  2. justinh

    preg_replace explanation

    Thank you so much - I understand it now after finally putting all the pieces together. I also figured out (from the link you provided) that the pattern string has to be enclosed by a delimiter, thus the two "/". Then the ending "i" mean case-insensitive alpha match. Just for anyone else that reads this post... It looks to me like someone could specialize just in regex coding! Thanks again.
  3. justinh

    preg_replace explanation

    Okay, I'll need a much greater breakdown that that... First, how to understand the value for $pattern. Then, where is the second matched pattern? (it looks like we are missing one) Then, why are there no spaces in the output string? It just looks way too complicated to replace only the day, as it looks like it is matching the entire string and carrying forward some of the original string instead of just what needs to be replaced.
  4. justinh

    preg_replace explanation

    I'm looking at this page about preg_replace: http://php.net/manual/en/function.preg-replace.php Which gives this example: <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?> The above example will output: April1,2003 I don't understand the transformation, how they go the answer. Can someone explain? Thanks, Justin
  5. justinh

    new line \n not working

    Thanks all. I've tried some of these ideas - good to know stuff!
  6. justinh

    new line \n not working

    Great info, dsonesuk! Now, can you give some details to help me understand better. Correct, the text is stacked in source. However, where else can I render PHP output besides a web page? I guess a file or a dialog box? So, is the bottom line that, if I am outputting to a web page, no need to bother with n, just use <br>? I guess I'm in rebellion a bit, because I want to use 'php' code in my PHP code and not HTML in my PHP code Thanks much! (yes, I'm a new newbie...)
  7. justinh

    new line \n not working

    I'm using UniServer Zero XI with PHP Version 5.4.42 (on Win7). I've tried different ways to force a new line in the web page, like with n. Only HTML BR tag seems to work. Here is an exmple: <!DOCTYPE html><html><body><?phpfunction makecoffee($type = "cappuccino"){ return "Making a cup of $type.n";}echo makecoffee();echo makecoffee(null);echo makecoffee("espresso");?></body><html> Output is: Making a cup of cappuccino. Making a cup of . Making a cup of espresso. But should be: Making a cup of cappuccino. Making a cup of . Making a cup of espresso. Is this a server configuration issue? Appreciate the input, Justin
  8. justinh

    skip enumeration of a value in form validation

    I fixed it by adding this to the beginning of the while loop: unset($query_vars['unwanted value']);
  9. Hi, I have a server-side PHP script to enumerate all the values in a form submission. After these values are processed, they are pushed to another script for another purpose. Some name/value pairs are required for secondary processing and some I don't care about. I want to know how to remove the names I don't care about for the secondary processing. Here is the code: <?php $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET") { $query_vars = $_GET; } elseif ($request_method == "POST") { $query_vars = $_POST; } reset($query_vars); $t = date("U"); $file = $_SERVER['DOCUMENT_ROOT'] . "ssfmgdform_" . $t; $fp = fopen($file,"w"); while (list ($key, $val) = each ($query_vars)) { fputs($fp,"<GDFORM_VARIABLE NAME=$key START>rn"); fputs($fp,"$valrn"); fputs($fp,"<GDFORM_VARIABLE NAME=$key END>rn"); if ($key == "redirect") { $landing_page = $val; } } fclose($fp); if ($landing_page != "") { header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); }?> So, if I know the name ($key) I'm interested in, can I inject something like 'if $key="XYZ", skip it' so it doesn't get processed downstream? By the time I get to this point, there is a name I don't need and don't want to process. I can barely walk around in this code, so I need to be spoon fed a bit. :-) Thanks, Justin
  10. justinh

    how to pass user message back to page from script

    Yes, I have to use the PHP script. I see other pages with PHP (I'm pretty sure) form validation that will give user feedback on the page (showing red text and such) with no apparent page transition - it looks like real-time validation. How do they do that? Is the page actually being refreshed and I just can't tell it?
  11. Hi, I'm using ASP web pages with a PHP server-side script to process a form with method=post. I'm checking the validity of a field in the PHP script, and if it fails there is code in the PHP to pop a message dialog (via javascript). The current workflow is this: 1) user submits form with bad data 2) simultaneously, a dialog is popped saying there is an error, and the form web page is gone and a blank page is shown 3) user selects the OK button and a javascript "history.go(-1)" is executed 4) user is now back to the form with previous values in the fields If the user put in good data, he would be advanced to a 'thank you' page. I'd like to avoid (2) and (3) with the page advancing then going back. In other words, I'd like the error check and message to be processed before the form page is left. Is what I want possible? Note that I can't modify the PHP much, and I'm very green at programming. :-) Thanks, Justin
  12. justinh

    templates, master file?

    Thank you all - that is what I needed!
  13. justinh

    templates, master file?

    Hi all,I'm a hobby web page developer and need to re-do some simple web sites. I'm just getting into CSS and don't know if this is the right forum or even a valid question . Here is the basic question: Is there a way to use a 'master' page where when you click a menu link it just loads different content, while keeping the header, footer, and menu areas static? Or, is there some way to create multiple content pages that stream/link in all the status areas (via CSS maybe)? I'm asking because if I make a change to a core item (menu, header, etc) I don't want to have to edit ten pages to make them all the same. I'm guessing all these huge commercial web site admins don't have to do that . I'd appreciate any hints or links or info! I think 'template' may be an applicable term here, but HTML editors seem to treat templates as just another HTML file used to create a new one. I'm thinking it may also mean a live template-like thing. Thanks,Justin