<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-18850028</id><updated>2011-09-27T02:24:57.122-07:00</updated><title type='text'>PHP</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://phpprogrammingguide.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://phpprogrammingguide.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Frank</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18850028.post-114204474967023566</id><published>2006-03-10T18:34:00.000-08:00</published><updated>2006-03-10T18:39:09.670-08:00</updated><title type='text'>Using ltrim is not the right answer sometimes.</title><content type='html'>In a PHP application I was debugging today for a company I found them using ltrim to remove a substring from the start of  a string which was producing weird results such as "tal" after invoking with "Total".&lt;br /&gt;&lt;br /&gt;When I asked their programmer why is he using ltrim, he replied to strip out a substring from the start of the string. &lt;br /&gt;&lt;br /&gt;His code was:&lt;br /&gt;&lt;p class="code"&gt;$clean=ltrim($unclean, "To");&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;So what's the problem? If a string starts with To such as in "ToTotal" (hypothetically), it incorrectly returns "tal" when the needed result was "Total" with just the first part of To stripped.&lt;br /&gt;&lt;br /&gt;I've posted the correct way to &lt;a href="http://phpprogrammingguide.blogspot.com/2006/03/php-regular-expressions-start-of-line.html"&gt;strip a substring using regular expressions&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18850028-114204474967023566?l=phpprogrammingguide.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpprogrammingguide.blogspot.com/feeds/114204474967023566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18850028&amp;postID=114204474967023566' title='43 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/114204474967023566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/114204474967023566'/><link rel='alternate' type='text/html' href='http://phpprogrammingguide.blogspot.com/2006/03/using-ltrim-is-not-right-answer.html' title='Using ltrim is not the right answer sometimes.'/><author><name>Frank</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>43</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18850028.post-114204444804700034</id><published>2006-03-10T18:26:00.000-08:00</published><updated>2006-03-10T18:34:08.070-08:00</updated><title type='text'>php regular expressions start of line: Removing a substring from the start of a string</title><content type='html'>When using regular expressions with PHP one must take care of a few minute details.&lt;br /&gt;&lt;br /&gt;For instance, today I received a request to debug an application.&lt;br /&gt;&lt;br /&gt;&lt;p class="code"&gt;&lt;br /&gt;$patterns[0] = "/^Top/";&lt;br /&gt;$replacements[0] = 'bear';&lt;br /&gt;$text=" Top/Top/Top/Business/Top/Accounting/Top";&lt;br /&gt;$text = preg_replace($patterns, $replacements, $text);&lt;br /&gt;echo $text . "\n\n";&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Can you spot the problem?&lt;br /&gt;&lt;br /&gt;Hint: running the above produces:&lt;br /&gt;&lt;p class="code"&gt; Top/Top/Top/Business/Top/Accounting/Top&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Here is the solution: many people mistakenly interpret ^ as the start of the line when in fact it represents the start of the string.&lt;br /&gt;&lt;br /&gt;Modifying the above regular expression to &lt;p class="code"&gt;&lt;br /&gt;$patterns[0] = "/^Top\//";&lt;br /&gt;$replacements[0] = 'bear/';&lt;br /&gt;$text="Top/Top/Top/Business/Top/Accounting/Top";&lt;br /&gt;#$text = preg_replace("/^(Top\/)/", '__', $text);&lt;br /&gt;$text = preg_replace($patterns, $replacements, $text);&lt;br /&gt;echo $text;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;produces:&lt;br /&gt;&lt;br /&gt;# bear/Top/Top/Business/Top/Accounting/Top&lt;br /&gt;&lt;br /&gt;which was the desired solution in this problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18850028-114204444804700034?l=phpprogrammingguide.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpprogrammingguide.blogspot.com/feeds/114204444804700034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18850028&amp;postID=114204444804700034' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/114204444804700034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/114204444804700034'/><link rel='alternate' type='text/html' href='http://phpprogrammingguide.blogspot.com/2006/03/php-regular-expressions-start-of-line.html' title='php regular expressions start of line: Removing a substring from the start of a string'/><author><name>Frank</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18850028.post-113359137335521424</id><published>2005-12-02T21:00:00.000-08:00</published><updated>2005-12-02T22:29:33.396-08:00</updated><title type='text'>Adding a button to toolbar in Nucleus.</title><content type='html'>Edit the file PAGEFACTORY.php&lt;br /&gt;&lt;br /&gt;Add&lt;br /&gt;&lt;blockquote&gt;$this-&gt;_jsbutton('blockquote',"blockquoteThis()",_ADD_BLOCKQUOTE_TT ." (Ctrl + Shift + Q)");&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;And&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;$this-&gt;_jsbutton('blockquote',"blockquoteThis()",'');&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Upload image button-blockquote.gif to admin/images directory&lt;br /&gt;&lt;br /&gt;Edit javascript/edit.js&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;function blockquoteThis() { insertAroundCaret('&lt;blockquote&gt;','&lt;/blockquote&gt;'); }&lt;/blockquote&gt;If the toolbar is enabled, the button should start working now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18850028-113359137335521424?l=phpprogrammingguide.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpprogrammingguide.blogspot.com/feeds/113359137335521424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18850028&amp;postID=113359137335521424' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/113359137335521424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/113359137335521424'/><link rel='alternate' type='text/html' href='http://phpprogrammingguide.blogspot.com/2005/12/adding-button-to-toolbar-in-nucleus.html' title='Adding a button to toolbar in Nucleus.'/><author><name>Frank</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18850028.post-113166477560896249</id><published>2005-11-10T15:15:00.000-08:00</published><updated>2005-11-10T15:19:35.623-08:00</updated><title type='text'>PHP Header 301 Redirect - Moved Permanently</title><content type='html'>From time to time, pages change location. At times like these, one can use PHP header function with 301 &lt;a href="http://www.technorati.com/tag/redirect" rel="tag"&gt;redirect&lt;/a&gt;  to notify website visitors that the page has moved, assuming the $location contains the new URL.&lt;br /&gt;&lt;br /&gt;Here is how you can use PHP header 301 redirect &lt;pre&gt;&lt;br /&gt;  header ('HTTP/1.1 301 Moved Permanently');&lt;br /&gt;  header ('Location: '.$location);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;More information about &lt;a href="http://www.technorati.com/tag/php" rel="tag"&gt;PHP&lt;/a&gt; header function can be obtained at &lt;a href="http://us3.php.net/header"&gt;PHP.net&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.technorati.com/tag/internet" rel="tag"&gt;Internet&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18850028-113166477560896249?l=phpprogrammingguide.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpprogrammingguide.blogspot.com/feeds/113166477560896249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18850028&amp;postID=113166477560896249' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/113166477560896249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18850028/posts/default/113166477560896249'/><link rel='alternate' type='text/html' href='http://phpprogrammingguide.blogspot.com/2005/11/php-header-301-redirect-moved.html' title='PHP Header 301 Redirect - Moved Permanently'/><author><name>Frank</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>10</thr:total></entry></feed>
