I've been customizing a WordPress install and have been needing to capture the output of the bloginfo() function, which simply echo's a string. I wanted to capture the echo into a variable without actually echo'ing the string. You can do so by leveraging PHP's output buffering functions. Here's how you do it:
echo 'Hello World';
$myStr = ob_get_contents();
$myStr will now contain 'Hello World' without actually outputting it to the screen.
For some reason, FCKEditor automatically wraps any content entered into the textbox with a <p> tag. This can cause for some problems in your layout when you're actually displaying the content. Instead of trying to fix this in your layout with CSS, there is a quick and easy way to turn the auto-wrap off in FCKEditor: Change the FCKConfig.EnterMode setting from 'p' to 'br'. There are a few ways to handle this:
- Edit fckconfig.js:
Change FCKConfig.EnterMode = 'p'; to FCKConfig.EnterMode = 'br';
- Change the setting programatically when you instantiate the object, like so (in PHP):
$oFCKeditor = new FCKeditor('description');
$oFCKeditor->BasePath = '/fckeditor/';
$oFCKeditor->Value = 'some text';
$oFCKeditor->Config['EnterMode'] = 'br'; // turn off auto <p> tags wrapping content
PHP & ionCube Loader: ‘The Loader must appear as the first entry in the php.ini file in Unknown on line 0′
I received the following in my Apache error_log when attempting to load the ionCube loader in my php.ini file:
PHP Fatal error: [ionCube Loader] The Loader must appear as the first entry in the php.ini file in Unknown on line 0
This is because ionCube must be loaded before any of the Zend extensions are. So if you have the Zend extension/optimizer loaded, your php.ini should look like this to get ionCube to work:
I ran into trouble when trying to pass a urlencode()'ed plus sign into a web address being processed by mod_rewrite.
$url = 'http://www.server.com/browsealpha/name+has+plus+in+it/';
$url = urlencode($url); // http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/
This $url variable gets echo()'d as a link in a page, so once it's clicked and loaded in the browser, I then needed mod_rewrite to translate that to the actual URL, which is:
Here is the RewriteRule I was using to match:
# match any name containing any combination of letters, numbers, and the % sign (to match urlencoded URLs)
RewriteRule ^browsealpha/([%\w]*)/?$ /browsealpha.php?name=$1 [QSA,L]
This rule should match http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/ but for some reason it wouldn't work. After hours of frustration, I found a few threads mentioning the need to urlencode() the string twice, like so:
IT WORKS!!! Apparently this is because mod_rewrite automatically decodes the urlencoded URL, so if you pass in %2B, PHP sees it as %2B0. If you double encode, mod_rewrite decodes the first one, and PHP receives the second one (which is now %2B, which is what we want).
If you're trying to write some text using PHP/GD & the imagettftext() function, you will of course need some TrueType fonts to work with. I've found a great set of fonts available for free: Webcore. Webcore contains all the fonts web designers constantly use, things like Arial, Tahoma, Verdana, Georgia, etc..
To install, simply download to your server and install the RPM (Fedora):
shell> wget http://avi.alkalay.net/software/webcore-fonts/webcore-fonts-3.0-1.noarch.rpm
shell> rpm -i webcore-fonts-3.0-1.noarch.rpm
These fonts will now be available to you in /usr/share/fonts/webcore/.
Make sure you specify the full path when calling imagettftext(), eg:
// Set the content-type
// Replace path by your own font path
$font = '/usr/share/fonts/webcore/arial.ttf';
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Hello world!';
// Add some text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
Your mileage may vary if you are using a different distribution, but the docs state that this RPM should work on other distros.
The instructions for doing so (here) seemed straightforward enough, but I ran into a few problems. So here's how I got PDFLib working with my PHP install on Fedora Core 4.
First we need to build PDFlib Lite from Source. Download it from here. Unpack it, then:
Easy enough. Now:
yum install automake
yum install php-devel
pecl install pdflib
(Note: php-devel is required because we need phpize which is used by the pecl command.)
The PECL install will ask you a question: "Path to PDFlib installation?" This is where I ran into problems. You must put /usr/local/ and NOT /usr/local/include because the script is hardcoded to look inside the include directory automatically. Once PECL finds pdflib.h it will continue and finish compiling our shared object, pdf.so. The script will install it for us in /usr/lib/php/modules/
Now we just have to tell PHP to load the SO. Open up php.ini and add the following line:
Save & exit, and restart your Apache with apachectl graceful. Now browse to a file containing the phpinfo() function and check to see if PDFlib is now active. If you see it, you're good to go!
NOTE: I ran into a problem with RPM GPG Keys at the automake install step. I was getting the following error:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID db42a60e
public key not available for autoconf-2.59-5.noarch.rpm
Retrieving GPG key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
The GPG key at file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora (0x4F2A6FD2)
is already installed but is not the correct key for this package.
Check that this is the correct key for the "Fedora Core 4 - i386 - Base" repository.
To get around this we need to import all the keys by run the following command:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
I found this solution in this thread.