<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ellis Web Development &#187; php</title>
	<atom:link href="http://ellisweb.net/category/code/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://ellisweb.net</link>
	<description>Thoughts &#38; Articles on ASP.net, C#, Software Development and Technology by Yaakov Ellis</description>
	<lastBuildDate>Mon, 07 May 2012 07:45:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using SyntaxHighlighter to Format Code in WordPress</title>
		<link>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/</link>
		<comments>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 08:04:15 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[syntaxhighlighter]]></category>

		<guid isPermaLink="false">http://ellisweb.net/?p=228</guid>
		<description><![CDATA[Based on a question in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others): Hack together your own display logic to format it … <a href="http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>Based on a <a href="http://beta.stackoverflow.com/questions/9051/what-is-best-blogging-host-for-programmerscode-formatting">question</a> in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others):</p>
<ol>
<li>Hack together your own display logic to format it as you see fit</li>
<li>Use the <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighlighter</a> JavaScript library</li>
<li>Use <a href="http://windowslivewriter.spaces.live.com/">Windows Live Writer</a> with the <a href="http://gallery.live.com/liveItemDetail.aspx?li=1f57bd9b-a692-4593-9e9e-e2962d9c0eee&amp;bt=9&amp;pl=8">Insert Code</a> plugin (I discuss that <a href="http://ellisweb.net/2007/11/trying-out-windows-live-writer/">here</a>)</li>
<li>For WordPress, use the <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a> plugin</li>
</ol>
<p>Coincidentally, I had heard Scott Hanselman talking about how he does code formatting just a couple of days ago, in <a href="http://hanselminutes.com/default.aspx?showID=143">Hanselminutes #125</a>, where he described how he posted code on his blog by putting it inside &lt;pre&gt;&lt;/pre&gt; tags, adding specific name and class attributes, and letting some JavaScript library do the formatting work. So I went to his blog, opened up a post with some code, and found my way to the <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighlighter</a> JavaScript library. This is a very nifty library that handles formatting very nicely for a number of popular programming and scripting languages, and seemed to have a very easy implementation. So I decided to implement it for formatting code on my site.<br />
<span id="more-228"></span></p>
<p><strong>Installing SyntaxHighlighter</strong></p>
<p>The basic steps that you have to follow are:</p>
<ol>
<li>Download the <a href="http://code.google.com/p/syntaxhighlighter/downloads/list">files</a></li>
<li>Upload the core JavaScript files, any JavaScript files related to languages that you would want to format, the swf and css files to somewhere on your server</li>
<li>Add references in your code to the different files</li>
</ol>
<p>A very good and more detailed guide on how you can do this with your template can be found in this <a href="http://fahdshariff.blogspot.com/2008/07/syntax-highlighting-code-in-webpages.html">blog post</a> by Fahd Sharif.</p>
<p><strong>Displaying Code</strong></p>
<p>Once you have the script, swf and css references integrated with your theme, you can post code using the following convention:</p>
<pre class="html" name="code">&lt;pre name="code" class="langName"&gt;
Type your code here
&lt;/pre&gt;</pre>
<p>If you are doing this in WordPress, you will need to use the HTML editor to insert this. Language name reference is <a href="http://code.google.com/p/syntaxhighlighter/wiki/Languages">here</a>.</p>
<p>Here is what is looks like in action:</p>
<pre class="c#" name="code">public static class StringExtension {
  // Extension method to return first letter of a string
  public static string GetFirstLetter(this string str) {
    string val = (str.Length &gt; 0) ? str.SubString(0,1) : "";
    return val;
  }
}</pre>
<p><strong>Fixing TinyMCE</strong></p>
<p>After I first got this implemented in my theme, I had some problems getting it to work on actual blog posts. I would go to HTML mode in the editor, put in the &lt;pre name=&#8221;code&#8221; class=&#8221;lang&#8221;&gt;&#8230;&lt;/pre&gt; syntax, go back to the Visual editor and finish my post, preview it, and no formatting would be applied. After checking the HTML source being output, I noticed that the <em>name=&#8221;code&#8221; </em>attribute of the <em>pre </em>tag was not being output. After some more investigation, I discovered that this attribute was being stripped by the TinyMCE editor when I switched from HTML to Visual editing modes.</p>
<p>It turns out that TinyMCE has its own built-in HTML validation that it employs when text is loaded into the Visual editor. Included in this is the ability to strip out attributes that are for whatever reason not &#8220;approved&#8221;. Tag:Name seems to be one of those.</p>
<p>One potential workaround would be to only use the HTML editor. Though I could do this, I like the Visual editor better when writing.</p>
<p>The alternative is to change the list of approved attributes for the <em>pre</em> tag so that <em>name</em> will no longer be stripped. After researching this a bit (references: <a href="http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/extended_valid_elements">1</a>, <a href="http://wordpress.org/support/topic/180502?replies=2#post-775393">2</a>, <a href="http://wordpress.org/support/topic/156276?replies=17#post-774445">3</a>), I did the following:</p>
<ol>
<li>Open up /wp-includes/js/tinymce/tiny_mce_config.php</li>
<li>Go to approximately line 298</li>
<li>Make the following edit (what you are doing here is giving tinyMCE an explicit list of attributes that are acceptable for the <em>pre</em> tag):</li>
</ol>
<pre class="php:firstline[298]" name="code">// Original: $content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});';
$content .= $ext_plugins . 'tinyMCE.init({extended_valid_elements : "pre[id|class|title|style|dir|lang|name|onclick|onkeypress]",' . $mce_options . '});';</pre>
<ol>
<li>Upload the new file</li>
<li>Clear your browser cache</li>
<li>Delete the /wp-content/uploads/js folder from the server</li>
<li>Do a hard-refresh of your editor page in WordPress</li>
</ol>
<p>You should now be able to toggle back and forth between HTML and Visual editor modes in WordPress without losing the pre:name attribute necessary for SyntaxHighlighter to work. You will have to repeat this whenever you upgrade WordPress.</p>
<p><strong>Why Not Just Use the Plugin</strong></p>
<p>WordPress junkies at this point are muttering to themselves: why go to all this trouble? There is already a <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/">plugin</a> that implements SyntaxHighlighter functionality and spares you all of this hard work. Here are the reasons why I chose to do this the hard way:</p>
<ol>
<li>The plugin ditches the &lt;pre&gt; syntax for a custom syntax that looks like this: [sourcecode language="lang"]CODE GOES HERE[/sourcecode]. While this eliminates the pre:name stripping issue that I mentioned before, it introduces something that in my opinion is much worse: tinyMCE now gets rid of any spatial formatting that you are using. I like to indent my code when necessary. If I am typing in the <em>pre</em> tag, tinyMCE respects all of my spacing, and does not strip any of it out (that is the whole purpose of <a href="http://www.w3schools.com/TAGS/tag_pre.asp"><em>pre</em></a>. Thus, I can save all of my indenting and spacing without any difficulties. If you are using a custom bracketed tag like the plugin does, tinyMCE strips a good deal of indenting and spacing, leaving code that just looks ugly.</li>
<li>The aforementioned code formatting issues carry over to the RSS feed as well. This way just works better.</li>
<li>The plugin includes all language JavaScript files. I don&#8217;t need to print Ruby code right now &#8211; why should I have to include the JS for it with my page?</li>
<li>Doing the implementation yourself gives greater flexibility in terms of using the <a href="http://code.google.com/p/syntaxhighlighter/w/list">different configuration options</a> that are available with SyntaxHighlighter.</li>
<li>It is more fun this way</li>
</ol>
<p><strong>Update:</strong> Engfer <a href="http://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/">lambasts me</a> for editing wordpress core files that will be overwritten whenever wordpress is upgraded. Instead, he created a wordpress plugin that will allow you to override and define the allowable attributes for any elements parsed by TinyMCE. It is available for download <a href="http://www.engfers.com/plugins/tinymce-valid-elements/">here</a> and is definitely a better way to go than manually editing files. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Deciphering PHP Error Messages and Blank Screens</title>
		<link>http://ellisweb.net/2006/10/deciphering-php-error-messages-and-blank-screens/</link>
		<comments>http://ellisweb.net/2006/10/deciphering-php-error-messages-and-blank-screens/#comments</comments>
		<pubDate>Wed, 11 Oct 2006 18:18:02 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false">http://www.ellisweb.net/2006/10/deciphering-php-error-messages-and-blank-screens/</guid>
		<description><![CDATA[My normal home is Visual Studio, ASP.net (1.1/2.0) and C#, with some CSS, HTML and JavaScript thrown in. Over the past week however, I have been working on an add-on to a client site written in PHP (using mySql as a DB backend). I am coding in Dreamweaver and am … <a href="http://ellisweb.net/2006/10/deciphering-php-error-messages-and-blank-screens/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>My normal home is Visual Studio, ASP.net (1.1/2.0) and C#, with some CSS, HTML and JavaScript thrown in. Over the past week however, I have been working on an add-on to a client site written in PHP (using mySql as a DB backend). </p>
<p>I am coding in Dreamweaver and am really missing Visual Studio, intellisense, robust debugging, design-time compile, being told right away when I make syntax mistakes and intelligent error messages. Since I have to upload to the test server before trying anything out, I have had to spend too much of my time trying to figure out why errors are occuring, backtracking, commenting out lines, upload and try again. </p>
<p>To save myself some googling in the future, and perhaps to help others in the same quandry, below are some of the most common error messages (or lack thereof) that I experienced during development, along with what they <strong>actually</strong> mean (since the words themselves rarely tell you what you need to know). If anyone has more to add, put them in the comments and I will add them below.</p>
<p><em>Parse error: parse error, unexpected $</em> &#8211; You forgot to close all of your brackets. (Or maybe you wrote an open-bracket sign &#8211; { &#8211; instead of a close-bracket sign)</p>
<p><em>Completely Blank Screen</em> &#8211; This one is the worst. It happens when you mess up php syntax. Note: the syntax error may be on the referenced page, or it may be on some page that you included, or that was included by an include (etc). The best part about it is <strong>you have no way of knowing where the error originated</strong> since the blank screen conveniently forgets to provide you with any error message. Here are the different things that caused this one to appear for me:</p>
<ul>
<li>Forgot a semi-colon at the end of a line. (This one is the most frustrating, because it is sometimes very hard to find, and because if I was using VS, I would find out about it when I was compiling my site, and not when I was trying to test)</li>
<li>Include the word <em>var</em> in a function declaration. For example, the following caused me a few hours of searching to find the cause of my blank screen: &#8220;function (<strong>var</strong> $id) { &#8230;&#8221; (error is in bold).</li>
<li>Include a dollar sign when you aren&#8217;t suppossed to. For example: &#8220;$name = $account-><Strong>$</Strong>Name&#8221; causes an error.</li>
<li>Not including a dollar sign when you are suppossed to. For example: &#8220;for ($i=0; i&lt;count($myArray); $i++) { &#8230;&#8221; causes an error (missing a dollar sign before the middle <em>i</em>)</li>
<li>Forgot a bracket (same as above, sometimes results in error message, sometimes in blank screen)</li>
<li>Entered &lt;?php at the beginning of a document instead of &lt;?<Strong>PHP</Strong> (stupid case-sensitivity&#8230;)</li>
</ul>
<p><em>Parse error: parse error, unexpected T_ELSE</em> &#8211; In writing an if/else structure, you forgot to include the closing bracket } between the end of <em>if</em> and the beginning of <em>else</em></p>
<p><em>Parse error: parse error, unexpected &#8216;=&#8217;</em> &#8211; You forgot to include a $ in front of a variable when making a value assignment. For example: &#8220;i = 5;&#8221; instead of &#8220;<strong>$</strong>i = 5;&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2006/10/deciphering-php-error-messages-and-blank-screens/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

