Truman Posted April 29, 2016 Author Share Posted April 29, 2016 Still the same thing...I give up and moving forward. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2016 Share Posted April 29, 2016 In Notepad++ under settings->preferences and select new documents what options are selected? Link to comment Share on other sites More sharing options...
Truman Posted April 29, 2016 Author Share Posted April 29, 2016 Windows, UTF-8 apply to opened ANSI files. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2016 Share Posted April 29, 2016 With no bom? Link to comment Share on other sites More sharing options...
Truman Posted April 30, 2016 Author Share Posted April 30, 2016 (edited) No BOM. By the way, what is bom? Edited April 30, 2016 by Truman Link to comment Share on other sites More sharing options...
Truman Posted May 1, 2016 Author Share Posted May 1, 2016 (edited) I'm working on multidimensiona arrays, I ran this code thru php checker and everything looks fine. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Larry Ullman's books and chapters.</title> </head> <body> <h1>Some of Larry Ullman's books</h1> <?php // Script 7.4 - books.php $phpvqs = array (1 => 'Getting Started with PHP', 'Variables', 'HTML Forms and PHP', 'Using Numbers'); $phpadv = array (1 => 'Advanced PHP Techniques', 'Developing Web Applications', 'Advanced Databe Concepts', 'Security Techniques'); $phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Creating Dynamic Web Sites', 'Introduction to MySQL'); $books = array ( 'PHP VQS' => $phpvqs, 'PHP Advanced VQP' => $phpadv, 'PHP and MySQL VQP' => $phpmysql ); print "<p>The third chapter of my first book is <i>{$books['PHP VQS'][3]}</i>.</p>"; print "<p>The first chapter of my second books is <i>{$books['PHP Advanced VQP'][1]}</i>.</p>"; print "<p>The fourth chapter of my fourt books is <i>{$books['PHP and MySQL VQP'][4]}</i>.</p>"; foreach ($books as $key => $value) { print "<p>$key: $value</p>\n"; } ?> </body> </html> But it sends message: Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP VQS: Array Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP Advanced VQP: Array Notice: Array to string conversion in C:\xampp\htdocs\my-site\books.php on line 24 PHP and MySQL VQP: Array  ------------------------------------------------------------------------------------------------------------------- line 24 is: print "<p>$key: $value</p>\n"; Edited May 1, 2016 by Truman Link to comment Share on other sites More sharing options...
Ingolme Posted May 1, 2016 Share Posted May 1, 2016 The issue is this: foreach ($books as $key => $value) { print "<p>$key: $value</p>\n"; } $value is an array, not a string, so you can't just put it inside a string. Link to comment Share on other sites More sharing options...
Truman Posted May 2, 2016 Author Share Posted May 2, 2016 (edited) So the author of this book is wrong? That's strange... p.s. I understand that you are right. It doesn't work. Edited May 2, 2016 by Truman Link to comment Share on other sites More sharing options...
dsonesuk Posted May 2, 2016 Share Posted May 2, 2016 You would need another key value to show other values in $phpvqs, $phpadv, $phpmysql 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted May 2, 2016 Share Posted May 2, 2016 Or run $value as an another foreach to retrieve each value <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Larry Ullman's books and chapters.</title> </head> <body> <h1>Some of Larry Ullman's books</h1> <?php // Script 7.4 - books.php $phpvqs = array(1 => 'Getting Started with PHP', 'Variables', 'HTML Forms and PHP', 'Using Numbers'); $phpadv = array(1 => 'Advanced PHP Techniques', 'Developing Web Applications', 'Advanced Databe Concepts', 'Security Techniques'); $phpmysql = array(1 => 'Introduction to PHP', 'Programming with PHP', 'Creating Dynamic Web Sites', 'Introduction to MySQL'); $books = array( 'PHP VQS' => $phpvqs, 'PHP Advanced VQP' => $phpadv, 'PHP and MySQL VQP' => $phpmysql ); print "<p>The third chapter of my first book is <i>{$books['PHP VQS'][3]}</i>.</p>"; print "<p>The first chapter of my second books is <i>{$books['PHP Advanced VQP'][1]}</i>.</p>"; print "<p>The fourth chapter of my fourt books is <i>{$books['PHP and MySQL VQP'][4]}</i>.</p>"; foreach ($books as $key => $value) { //key and value(array) for books array print "<p>$key:"; $join = ""; foreach ($value as $value2) { //value(array) of above read out as individual values $join.= " $value2, "; } $join = rtrim($join, ', '); print $join; print ".</p>\n"; } ?> </body> </html> 1 Link to comment Share on other sites More sharing options...
Ingolme Posted May 2, 2016 Share Posted May 2, 2016 So the author of this book is wrong? That's strange... p.s. I understand that you are right. It doesn't work. A simple fix would be to join the array elements into a string. foreach ($books as $key => $value) { print "<p>$key: " . implode(', ', $value) . "</p>\n"; } 1 Link to comment Share on other sites More sharing options...
Truman Posted May 3, 2016 Author Share Posted May 3, 2016 Thanks, and I learn't a new function. Link to comment Share on other sites More sharing options...
Truman Posted May 13, 2016 Author Share Posted May 13, 2016 (edited) I'm making now a template and within header.html I placed two date functions but when I run the code I don't see them on the browser. Don't know why, everything is by the book. <!DOCTYPE html> <head> <title> </title> <?php // Print the page title if (defined('TITLE')) { print TITLE; } else { print 'Raise High the Roof Beam! A J.D. Salinger Fan Club'; } ?> </head> <body> <div id="wrapper"> <div id="header"> <p class="description">A J.D. Salinger Fan Club</p> <h1><a href="index.php">Raise High the Roof Beam!</a></h1> <ul id="nav"> <li><a href="books.php">Books</a></li> <li><a href="#">Stories</a></li> <li><a href="#">Quotes</a></li> <li><a href="login.php">Login</a></li> <li><a href="register.php">Register</a></li> </ul> </div><!-- header --> <div id="sidebar"> <h2>Favorite Quotes</h2> <p class="news">I don't exactly know what I mean by that, but I mean it.< /br> <em>Catcher in the Rye</em></p> <p class="news">I privately say to you, old friend...please accept from me this unpretentious bouqet of early-blooming parentheses: (((()))). <em>Raise high the Roof Beam, Carpenters and Seymour: An Introduction</em></p> <p><?php date_default_timezone_set('America/New_York'); print date('g:i a l F j'); ?></p> </div><!-- sidebar --> <div id="content"> <!-- BEGIN CHANGEALBE CONTENT. --> <!-- Script 8.6 - header.html --> Edited May 13, 2016 by Truman Link to comment Share on other sites More sharing options...
Ingolme Posted May 13, 2016 Share Posted May 13, 2016 That code looks correct. Perhaps you are not looking at the right page in your browser. Link to comment Share on other sites More sharing options...
Truman Posted May 13, 2016 Author Share Posted May 13, 2016 (edited) I don't think so, this html executes and I see content. Â here is the page: Edited May 13, 2016 by Truman Link to comment Share on other sites More sharing options...
dsonesuk Posted May 13, 2016 Share Posted May 13, 2016 Err? have you setup the server to run .html or .htm as .php? or is this a mod_rewrite feature? Â Did you do the usual and clear history/cache everything? Â Also disable add-on ABP running on localhost. Link to comment Share on other sites More sharing options...
Ingolme Posted May 13, 2016 Share Posted May 13, 2016 If you wish to use PHP then the file extension needs to be changed to .php. You could also change the server settings to run PHP code in files with the .html extension but I don't think that is necessary. 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted May 13, 2016 Share Posted May 13, 2016 Err? have you setup the server to run .html or .htm as .php? or is this a mod_rewrite feature? Â Did you do the usual and clear history/cache everything? Â Also disable add-on ABP running on localhost. Link to comment Share on other sites More sharing options...
Truman Posted May 14, 2016 Author Share Posted May 14, 2016 If you wish to use PHP then the file extension needs to be changed to .php  Thank you, I didn't know this...In the book it's not mentioned. Now it works fine. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 14, 2016 Share Posted May 14, 2016 Hang on! If you have not set it up to run php code on html extension page, how come the php code did not show up on the output i.e the page itself, that does not make sense? Link to comment Share on other sites More sharing options...
Ingolme Posted May 14, 2016 Share Posted May 14, 2016 The PHP code is within <?php ?> tags, which are interpreted as processing instructions (similar to <?xml ?>). A good browser will not display those on the page. 1 Link to comment Share on other sites More sharing options...
Truman Posted May 16, 2016 Author Share Posted May 16, 2016 Can you please take a look at this code, from some reason it doesn't work. <?php // Script 8.9 - register.php define ('DEFINE', 'register'); include('templates/header.html'); print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other things</p>'; print '<style type="text/css" media="screen"> .error { color: red; } </style>'; if ($_SERVER['REQUESTED_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name!</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name!</p>'; } if (empty($_POST['email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirm password.</p>'; } if (!$problem) { print '<p>You are now registered.</p>'; } $_POST = array(); } else { print '<p class="error">Please try again!</p>'; } ?> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) { print htmlspecialchars($_POST['first_name']); } ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) { print htmlspecialchars($_POST['last_name']); } ?>" /></p> <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print htmlspecialchars($_POST['email']);} ?> /></p> <p>Password: <input type="password" name="password1" size="20" value="<?php if (isset($_POST['password1']) { print htmlspecialchars($_POST['password']); } ?> /></p> <p>Confirm Password: <input type="password" name="password2" size="20" value="<?php if (isset($_POST['password2'])) { print htmlspecialchars ($_POST[password2']); } ?>" /></p> <p><input type="submit" name="submit" value="Register!"> /></p> </form> <?php include('templates/footer.html'); ?> I receive a note:Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\register.php on line 46 Â line 46 is: <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print Link to comment Share on other sites More sharing options...
dsonesuk Posted May 16, 2016 Share Posted May 16, 2016 Look carefully at if condition count open parenthesis compared to closed parenthesis 1 Link to comment Share on other sites More sharing options...
Truman Posted May 19, 2016 Author Share Posted May 19, 2016 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>View Your Settings</title> <style type="text/css"> body { font-size: x-large; color: #999; } <?php // Script 9.2 - view_settings.php if (isset($_COOKIES['font_size'])) { print "\t\tfont-size: " . htmlentites($_COOKIES['font_size']) . "; \n } else { print "font-size: medium;"; } if (isset($_COOKIES['font_color'])) { print "color: #" . htmlentities($_COOKIES['font_color']) . ";\n"; } else { print "\t\tcolor: #ooo;"; } ?> </style> </head> <body> <p><a href="customize.php">Customize your settings.</a></p> <p><a href="reset.php">Reset your settings.</a></p> <p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p> </body> </html> Can you please tell me why I receive this message> Parse error: syntax error, unexpected 'size' (T_STRING) in C:\xampp\htdocs\my-site\view_settings.php on line 15 line 15 is: print "font-size: medium;"; Link to comment Share on other sites More sharing options...
justsomeguy Posted May 19, 2016 Share Posted May 19, 2016 Look at the coloration of the code, you're missing a quote. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now