R
E
S
O
U
R
C
E
S
       Question Index      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: side or top popup menus, buttons, image rotators, navbars, tons more.
_______________________

Send us your questions and wittiest comments.
_______________________

Report errors on our site.
_______________________

Share your neatest DHTML examples with us; we may publish them.
_______________________


_______________________

      QUESTION INDEX      

Question Index
Browser Insanity
JavaScript
Animation
Buttons and Menus
CSS and HTML
PHP
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS

 INFORMATIVE ARTICLES 

Menus-and-Buttons-
Part-I.htm


Menus-and-Buttons-
Part-II.htm


Change-Div-Size-Color-
and-Location-with-the-
W3C-DOM.htm


Bouncing-Ball-Animation-
with-the-W3C-DOM.htm


Style-Changes-with-the-
W3C-DOM.htm


Animation-with-the-
W3C-DOM.htm


Window-Play-and-Some-
Important-DOM-Methods.htm


Using-getElementsByTagName
-and-getElementsByName.htm


The-CSS-Resources-Intro-
Page.htm


Convert-Word-Files-to-HTML-
and-Install-Editor2-to-
Use-Instead-of-NotePad.htm


CSS-Issues.htm

What Are Fifteen Simple Methods of Doing Web-Page Pop-ups?

Security levels from Javascript and PHP input filtering

What is a regular expression general input validator?

What is a regular expression user name validator?

What is a regular expression password validator?

What is a regular expression email validator?

What is a regular expression URL validator?

How can I convert a Javascript array to a PHP array?

How can I Dynamically Create Input Boxes with Validation?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do I add html to a web page with JavaScript, PHP or ssi includes?

How do I add html to a web page with JavaScript includes?


PHP

How do you put PHP variables in URL and link text?

What is PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts with a captcha?

What is Administrator PHP Code for Multiple PSB Hosts?

What's the PHP code for a script for a PSB?

What's the PHP code for a script for PSB updating?

What's the PHP code for a script if you forgot your user name?

What's the PHP code for a script if you forgot your password?

What's the PHP code for a script to change a member's email address?

What's the PHP code for a script to connect to a MySQL database?

What's the PHP code for a script to close a member's account?

What's the PHP code for a script to edit group member?

What's the PHP code for a script to add group member?

What's the PHP code for a script to reset a MySQL table's data to its original?

What's the PHP code for a script to edit a MySQL table's data?

What's the PHP code for a script to change a username?

What's the PHP code for a script to change a password?

What's the PHP code for a script to delete group member?

What's the PHP code for a script to view membership data?

What's the PHP code for a script to change an administrator's password?

What's the PHP code for a script to logout?

What's the PHP code for a script to login?

Security levels from Javascript and PHP input filtering

Security levels and PHP

How can I convert a Javascript array to a PHP array?

What is PHP Code to Prevent Duplicate Data Input - Like User Names or Members?

What is PHP Code for PSB Status Update for Multiple PSB Hosts?

How do I sort 1 PHP array and have the other arrays sort in parallel to how the first array sorts?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do you do PHP-to-JavaScript String Conversion with No JSON?

How do you Convert PHP String to JavaScript String?

How do you Post a JavaScript Array to a PHP Array?

How do you send a value to PHP using JavaScript?

Info on unwanted primary field auto-sorting

How can I do instant article font size, font family, and paragraph formatting with radio buttons?

How can I create custom HTML tags that are safer for MySQL databases?

How can I edit text from MySQL databases by using a textarea box?

How can I highlight matched search terms in a MySQL database table search?

How can I search using not only exact phrase matching but also a series of words to match in a MySQL database table search?

What's the code for an Ajax and PHP Based Input Filter?

Ajax and PHP Based Insult Auto-Completer

How can I use PHP and MySQL for Checking Key Codes to Allow Update to a New Software App Version?




Personal Status Boards (PSB™)

Standard Free PSB

PSB Pro Version

Social PSB

Social PSB Plus (with Email)

Business PSB

Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement




Article Content Management System

Content Management System Introduction

Content Management System—Article Navigation

Content Management System—Article Indexing

Content Management System—Article Editing

Content Management System—Article Searching

Content Management System—Article Deleting

Content Management System—Article Writing

Content Management System—Article Reading

What are the terms of use for our Article Content Management System?




Website Directory Content Management System

Website Directory Navigation

Website Directory—Delete Category

Website Directory—Delete URL

Website Directory—Add URL

Website Directory—Add Category

Website Directory—Directory Creating

Website Directory—View by Category (Demo Code)

Website Directory—View by URL (Demo Code)

Website Directory—View by Category (Demo)

Website Directory—View by URL (Demo)

Website Directory—View

Website Directory—View (Demo)




Photo Gallery Content Management System

Code for Photo Gallery Navigation

Code for Photo Gallery—View

Code for Photo Gallery—Create

Code for Photo Gallery—Add Category

Code for Photo Gallery—Delete Category

Code for Photo Gallery—Add Photo

Code for Photo Gallery—Delete Photo

Code for JavaScript Photo Gallery

JavaScript Photo Gallery




Forum Content Management System

Forum: home page

Forum: search

Forum: login

Forum: topic and replies viewing page

Forum: add topic to database

Forum: add reply to database

Forum: edit topic in database

Forum: create topic in database

Forum: delete topic in database

Forum: delete reply in database

Forum: delete user account in members table



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

JavaScript Object Notation (JSON) for PHP to JavaScript Conversions

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language. But best of all for our purposes, it makes PHP to JavaScript conversions a snap which would otherwise be nearly impossible! Below, we convert a PHP array to a JavaScript array. Fat chance you'll pull this one off without JSON! (For more on this issue, see PHP-to-JavaScript-String-Conversion-with-No-JSON.html. Many people assume you can convert PHP strings to JavaScript without JSON just because numbers convert well. It ain't so. However, at the bottom of this page you'll find many things you can do with PHP that avoid any conversion needs. PHP can do more than most people think!) This JSON stuff is especially useful for pulling data from MySQL databases and making it available to JavaScript.

<?php

$temperatures=array('hot','cold','lukewarm');

echo "PHP array of 3 values";
echo "<br><br>";
echo $temperatures[0]." ";
echo $temperatures[1]." ";
echo $temperatures[2];

?>

<script language="javascript">

var temperatures = <?php echo json_encode($temperatures); ?>;

alert("JavaScript array of 3 values: "+temperatures);

alert("JavaScript array of 3 values: \n"+temperatures[0]+"\n "+temperatures[1]+"\n "+temperatures[2]);

</script>

PHP to JavaScript conversion of strings requires JSON unless you use a very crude solution. Note that the same JSON encode function that works on arrays works on strings. But lots of luck making the standard non-JSON method work!

<?php

$temperatures="hot";

echo "PHP string value";
echo "<br><br>";
echo $temperatures;

$temp_hotter="now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party now is the time for all good men to come to the aid of the party";

echo "<br><br>";
echo "PHP string value";
echo "<br><br>";
echo $temp_hotter;

?>

<script language="javascript">

var temperatures = <?php echo json_encode($temperatures); ?>;

var temp_hotter = <?php echo json_encode($temp_hotter); ?>;

alert("JavaScript string values: "+temperatures+" \n\n"+temp_hotter);

document.write("<br><br><br>But if you try to declare this string in PHP:<br><br><b>$temp=\"cold\";</br><br><br>and convert it in JavaScript with:<br><br><b>var temp = <?php echo $temp; ?>;</br><br><br>IT WON'T WORK, AND NEITHER WILL ANY OTHER STRINGS WITHOUT JSON!");

</script>

PHP to JavaScript conversion of numbers requires JSON for accuracy if the number has over 16 digits. Note that the same JSON encode function that works on arrays works on numbers. But lots of luck making the standard non-JSON method work if your number has 17 or more digits! Of course, you can always break the number in half and send 2 numbers the standard way, then join (concatenate) them back up once you're in JavaScript. We've tried this—it's crude but it works.

<?php

$temperatures="12345678901234567890";

echo "PHP 20-digit numeric value";
echo "<br><br>";
echo $temperatures;
echo "<br><br>";

$humidity="1234567890123456";

echo "PHP 16-digit numeric value";
echo "<br><br>";
echo $humidity;

?>

<script language="javascript">

var temperatures = <?php echo json_encode($temperatures); ?>;

alert("JavaScript numeric value--note no rounding off of the last 4 digits of a 20-digit numeric value using JSON: "+temperatures);

var temp = <?php echo $temperatures; ?>;

alert("JavaScript numeric value--note the rounding off of the last 4 digits of a 20-digit numeric value without JSON: "+temp);

var humid = <?php echo $humidity; ?>;

alert("JavaScript numeric value--note no rounding off--numbers up to 16-digits don't need JSON: "+humid);

</script>

PHP to JavaScript conversion of floating point numbers requires JSON for accuracy if the number has over 16 digits. Note that the same JSON encode function that works on arrays works on floating point numbers. But lots of luck making the standard non-JSON method work if your floating point number has over 17 digits!

<?php

$temperatures="1234567890.1234567890";

echo "Convert PHP Decimal/Floating Point Number to JavaScript Decimal/Floating Point Number";
echo "<br><br>";
echo "PHP 20-digit numeric decimal value";
echo "<br><br>";
echo $temperatures;
echo "<br><br>";

$humidity="1234567890.1234567";

echo "PHP 17-digit numeric decimal value";
echo "<br><br>";
echo $humidity;

?>

<script language="javascript">

var temperatures = <?php echo json_encode($temperatures); ?>;

alert("JavaScript numeric value--note no rounding off of the last 3 digits of a 20-digit numeric value using JSON: "+temperatures);

var temp = <?php echo $temperatures; ?>;

alert("JavaScript numeric value--note the rounding off of the last 3 digits of a 20-digit numeric value without JSON: "+temp);

var humid = <?php echo $humidity; ?>;

alert("JavaScript numeric value--note no rounding off--numbers up to 17-digits don't need JSON: "+humid);

var humider=2+humid;

alert("JavaScript numeric value--we added 2 to it--see--it\'s real: "+humider);

</script>





Insert, Not Convert!



As you can see below, PHP inserts are easier than messing with PHP-to-JavaScript conversions. You can stick blocks of PHP code into query strings in URLs which are in JavaScript window.location objects which are in PHP echo statements. Or put blocks of PHP code into action attributes in form tags, adding query strings to the URLs. Or put blocks of PHP code into query strings in URLs in HTML links or even have them be the whole URL. You need not use stripslashes() functions, of course, but if you added the slashes with mysql_real_escape_string() before storing the data in MySQL tables, it's a good precaution to take. The JSON function json_encode() will allow you to convert strings to JavaScript seamlessly, but only numbers convert nicely without JSON, as shown above.

You can stick blocks of PHP into HTML text statements, in forms, in tables, and all this seamlessly, as long as you avoid the urge to convert the PHP to anything. Note the use of htmlentities() and stripslashes() both when using values freshly pulled out of MySQL databases. See security-levels-from-javascript-and-php-input-filtering.html for security issues at stake that prompt the use of htmlspecialchars() and htmlentities().

You can put a block of PHP code in the value attribute of an HTML form input tag.

echo '<script language="javascript">alert("You must be the topic author to edit this topic.");window.location = "cms-view-topic.php?id='.$id.'&username='.$U.'"; </script>'; //THIS WILL WORK

<form id="form1" name="form1" method="post" action="cms-edit-topic.php?id=<? echo stripslashes($id); ?>&username=<? echo stripslashes($U); ?>"> //THIS WILL WORK

<a href="cms-view-topic.php?username=<? echo stripslashes($U); ?>&id=<? echo stripslashes($id); ?>">Return to Topic-don't edit</a> //THIS WILL WORK

<a href="<? echo stripslashes($CoolURL); ?>">Go somewhere</a> //THIS WILL WORK

var c = <?php echo json_encode($detail); ?>; //THIS WILL WORK

var c = <?php echo $detail; ?>; //THIS WILL NOT WORK

The best ballpark is <?php echo $parks; ?>. //THIS WILL WORK

var c = <?php echo $parks; ?>; "The best ballpark is "+c+"."; //THIS WILL NOT WORK

var c = <?php echo $parks; ?>; "The best ballpark is ".c."."; //THIS WILL NOT WORK

<?php $c="Yankee Stadium"; echo "The best ballpark is ".$c."."; //THIS WILL WORK ?>

THE CODE BELOW WILL WORK
<table><tr><td><b><? echo htmlentities(stripslashes($rows['topic']), ENT_QUOTES); ?></b></td></tr></table>

THE CODE BELOW WILL WORK
<form method="post" action=" " name="whatever">
<table><tr><td><input name="id" type="hidden" value="<? echo htmlentities(stripslashes($id), ENT_QUOTES); ?>"></td></tr></table></form>

THE CODE BELOW WILL WORK
<tr><td><b>Email :</b> <? if($U=="xyz_secret_stuff"){echo htmlentities(stripslashes($rows['email']), ENT_QUOTES);}else{echo "(private)";}
?></td></tr>

THE CODE BELOW WILL WORK
<tr><td><b>Topic is: </b><? $open="Open";if($rows['open']=="0"){$open="Closed";}; echo $open; ?></td></tr>

THE CODE BELOW WILL WORK
<?php $j=$j+10; if($i<$num_topics){echo "<div class='over2'><a href='cms-blog.php?username=".stripslashes($U)."&j=".$j."&mode=-2'><B>More . . .</B></a></div>";} ?>