{"id":3800,"date":"2013-08-22T06:01:55","date_gmt":"2013-08-21T20:01:55","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3800"},"modified":"2013-08-22T06:01:55","modified_gmt":"2013-08-21T20:01:55","slug":"phpjavascript-eval-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascript-eval-primer-tutorial\/","title":{"rendered":"PHP\/Javascript Eval Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PPHP\/Javascript Eval Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/PHP_Javascript_Eval.jpg\" title=\"PHP\/Javascript Eval Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript Eval Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s tutorial adds an onion layer on top of an answer of a question on <a target=_blank title='Relevant Yahoo Answers question ... thanks, Jaxi' href='http:\/\/au.answers.yahoo.com\/question\/index?qid=20130815213021AABPvC1'>Yahoo Answers<\/a>. This is the way I really like to program. Get the essence right first, then build onion layers on top, and have supervisors of supervisors of supervisors \u2026 for Onion a then Onion 1-a then Onion A-1-a \u2026 then Onion of the Eval Dimension &#8230; what! &#8230; yes, good old much maligned (because, yes, it needs to be used with caution for software security reasons), Eval!   What is Eval?   Starting to sound familiar with all the election talk?   Eval is the construction of a line of code and the language calculating the answer on the fly, and both <a target=_blank title='PHP eval' href='http:\/\/php.net\/manual\/en\/function.eval.php'>PHP<\/a> and <a target=_blank title='Javascript eval' href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp'>Javascript<\/a> have their own &#8220;Eval&#8221;s, pretty obviously achieving completely different things (being as PHP is serverside and the Javascript am using is clientside), but both happening to be useful for the achievement of this tutorial, where we take a file with calculator type statements in it, like &#8220;56 * 23 \/ 234=&#8221;  and constructing a program to answer the calculator type question.   Well, did this in PHP\/Javascript and then realized, as I slipped on a non-existant onion peel, that this method could be extended for a CSV input scenario.   So the end result is a webpage that accepts via the URL with an ?infile= clause, the input data in either style of format, and the extra &#8220;get&#8221; parameter &#038;interactive=y to say you want a Javascript alert box for each calculator result, rather than seeing all the results at once (also available are &#038;leaveinquote=y and &#038;justanswer=y (or n) and the &#038;leavequote=y&#038;justanswer=y would allow a comma-separated series of strings be concatenated and output to the screen if you choose the default Mathematical operators of (all) + signs).\n<\/p>\n<p>Here is a link to some downloadable PHP programming source code which can be renamed to <a target=_blank title='eval_js_php.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/eval_js_php.php_GETME'>eval_js_php.php<\/a> for your perusal.<\/p>\n<p>Enjoy the live <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/' title='Tutorial link'>interactive tutorial<\/a> (or one we baked before <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/?infile=evaluatorcomma.csv' title='Tutorial link'>here<\/a>, or one that was half-baked <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Eval\/?infile=evaluator.txt&#038;interactive=y' title='Only kidding'>here<\/a> or maybe you&#8217;d like some <a target=_blank title='Macarthur Park' href='https:\/\/www.youtube.com\/watch?v=CPMpeNDIGdk'>&#8220;sweet, green icing flowing down&#8221;<\/a>), as we depart with Wikipedia&#8217;s view of  <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Eval' title='Wikipedia information about debugging'>Eval<\/a>.<\/p>\n<blockquote>\n<p>In some programming languages, eval is a function which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval. The input to eval is not necessarily a string; in languages that support syntactic abstractions (like Lisp), eval&#8217;s input will consist of abstract syntactic forms.<\/p>\n<\/blockquote>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3800' onclick='var dv=document.getElementById(\"d3800\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Software\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3800' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s tutorial adds an onion layer on top of an answer of a question on Yahoo Answers. This is the way I really like to program. Get the essence right first, then build onion layers on top, and have supervisors &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascript-eval-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,33,37],"tags":[283,399,576,652,932,997,1319,1488],"class_list":["post-3800","post","type-post","status-publish","format-standard","hentry","category-elearning","category-software","category-tutorials","tag-csv","tag-eval","tag-html","tag-javascript","tag-php","tag-programming","tag-tutorial","tag-yahoo-answers"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/3800"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=3800"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/3800\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=3800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=3800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=3800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}