Friday, February 25, 2011
Tip: Strip characters at the end of the string in PHP
rtrim('http://yahoo.com./', '/'), ltrim('/jab/', '/')
Thursday, February 24, 2011
NOTES: Photoshop Canvas Size
This might be a newbie tip and maybe just a reminder for me in the future.
If you want to edit your container's size in photoshop without affecting or distorting the layers use
CANVASS SIZE instead of image size
If you want to edit your container's size in photoshop without affecting or distorting the layers use
CANVASS SIZE instead of image size
Wednesday, February 16, 2011
Apache rewriteRules act differently on different hosts/shared hosts. A Zend Framework installation
I was testing the Zend Framework on a shared host and it happens that they do not allow modication of your Apache virtual host Document Root. Meaning if you are using a Zend Framework or some other CMS that requires you to point to a directory within your document root say a sub directory named /Public you may have some problems.
To solve this problem this .htaccess worked on my shared host:
credits too: http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
The above .htaccess worked fine in my Shared host but DO NOT work in my own dev box running Ubuntu with PHP as an Apache module. I keep getting "Request exceeded the limit of 10 internal redirects due to probable configuration error." problems in Apache.
To rectify this i have to edit the .htaccess again to:
RewriteRule ^public/.*$ public/index.php [NC,L]
I also have to "retain" the original .htaccess that comes from ZF in the Public directory where as in my shared host i have to REMOVE it or I will keep getting Error 500.
To conclude, I have no idea why different rewrites work from the other. I dont know if its Apache version, PHP version, compilation whatevert. I am pretty much clueless actually but try to mix match i guess if things doesnt make sense?
To solve this problem this .htaccess worked on my shared host:
credits too: http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ public/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ public/$1 [NC,L]
RewriteRule ^public/.*$ public/index.php [NC,L]
RewriteRule ^public/.*$ public/index.php [NC,L]
The above .htaccess worked fine in my Shared host but DO NOT work in my own dev box running Ubuntu with PHP as an Apache module. I keep getting "Request exceeded the limit of 10 internal redirects due to probable configuration error." problems in Apache.
To rectify this i have to edit the .htaccess again to:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ public/index.php [NC,L]
I also have to "retain" the original .htaccess that comes from ZF in the Public directory where as in my shared host i have to REMOVE it or I will keep getting Error 500.
To conclude, I have no idea why different rewrites work from the other. I dont know if its Apache version, PHP version, compilation whatevert. I am pretty much clueless actually but try to mix match i guess if things doesnt make sense?
Sunday, February 13, 2011
Problem Saving Persistent Network Connections in Windows 7
If you try to map a network drive in Windows 7, you may have experience that it wont connect to it upon reboot of your system, even if you check "save credentials".
I've google the solution for this problem but you may dig a lot of web sites to find it so ill lay it out here for someone who may need it.
Go to:
Start -> Control Panel -> User Accounts & Family Settings -> Credential Manager
You may see under Windows Credential you current mapped account credentials.
Click "Add a Windows Credentials" and enter your network account AGAIN. This will override your current credentials. That should fix the problem and should connect after reboot now.
The problem is with the persistence of you connection. You may notice under you credential's persistence that it may be set to "per session". It has to be set to "enterprise" and the solution above should fix that!
I've google the solution for this problem but you may dig a lot of web sites to find it so ill lay it out here for someone who may need it.
Go to:
Start -> Control Panel -> User Accounts & Family Settings -> Credential Manager
You may see under Windows Credential you current mapped account credentials.
Click "Add a Windows Credentials" and enter your network account AGAIN. This will override your current credentials. That should fix the problem and should connect after reboot now.
The problem is with the persistence of you connection. You may notice under you credential's persistence that it may be set to "per session". It has to be set to "enterprise" and the solution above should fix that!
Friday, February 11, 2011
XML Encoding Issues
Thought it might be worth to document my experience today since I tend to forget most of the solutions for my problems.
It is important to be aware of XML limitations specially when it relates to encoding. When using UTF-8 since its only an 8 bit character it will not convert a lot of characters specially the ones coming from ISO-8859-1 html enitities. You will keep getting errors in your XML!! One solution is to change the encoding of your XML to match your encodings and the other is to convert these characters to UNICODE. I chose the latter solution.
Here's a usefull script I plucked in from PHP.net that will convert html entities to UNICODE (credits to php.net):
public static function htmlentitiesToUnicode($input)
{
$htmlEntities = array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$entitiesDecoded = array_keys(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$num = count ($entitiesDecoded);
for ($u = 0; $u < $num; $u++) {
$utf8Entities[$u] = '&#'.ord($entitiesDecoded[$u]).';';
}
return str_replace ($htmlEntities, $utf8Entities, htmlentities($input, HTML_ENTITIES));
}
Another problem I encountered is within the transmission and reading of the XML data. I used PHP's SimpleXML to convert my XML to objects. One problem SimpleXML is giving me is eventhough the html entities are converted to unicodes, it is giving out jibberish characters as output!
Heres a sample of what i am talking about:
Original encoding: résumés
UNICODE encoding (XML): résumés
Jibberish SimpleXML translation: résumés
fortunately there is a simple solution for this problem....iconv()
just use
$val = iconv('UTF-8', 'ISO-8859-1', $val);
and hopefully that should solve your encoding problems.
It is important to be aware of XML limitations specially when it relates to encoding. When using UTF-8 since its only an 8 bit character it will not convert a lot of characters specially the ones coming from ISO-8859-1 html enitities. You will keep getting errors in your XML!! One solution is to change the encoding of your XML to match your encodings and the other is to convert these characters to UNICODE. I chose the latter solution.
Here's a usefull script I plucked in from PHP.net that will convert html entities to UNICODE (credits to php.net):
public static function htmlentitiesToUnicode($input)
{
$htmlEntities = array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$entitiesDecoded = array_keys(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$num = count ($entitiesDecoded);
for ($u = 0; $u < $num; $u++) {
$utf8Entities[$u] = '&#'.ord($entitiesDecoded[$u]).';';
}
return str_replace ($htmlEntities, $utf8Entities, htmlentities($input, HTML_ENTITIES));
}
Another problem I encountered is within the transmission and reading of the XML data. I used PHP's SimpleXML to convert my XML to objects. One problem SimpleXML is giving me is eventhough the html entities are converted to unicodes, it is giving out jibberish characters as output!
Heres a sample of what i am talking about:
Original encoding: résumés
UNICODE encoding (XML): résumés
Jibberish SimpleXML translation: résumés
fortunately there is a simple solution for this problem....iconv()
just use
$val = iconv('UTF-8', 'ISO-8859-1', $val);
and hopefully that should solve your encoding problems.
Monday, February 7, 2011
Tip: Enabling Apache Mod_Proxy
If you want to "mask" a URL say contents in http://myurl.com/index.php would pull the content of http://myurl2.com/index.php so when you view http://myurl.com/index.php you are actually viewing http://myurl2.com but URL stays in http://myurl.com. You can do this using Apache's Mod_Rewrite via Mod_Proxy.
You should also enable dependent modules like
proxy_connect.c
proxy_ftp.c
proxy_http.c
Then in your .htaccess in http://myurl.com/ you can do something like:
RewriteRule ^path/to/myurl/(.*)$ http://myurl2/$1 [P,L]
Remember the P flag which stands for proxy!!
Subscribe to:
Posts (Atom)