Twitter I hate this fecking cold. 5 days later and it won't go. #fb 1 week ago


Showing results 1 - 16 of 20 for the tag: PHP.

Dec 09
11th

Plugin error “cannot yet handle MBCS in html_entity_decode”


Today I’ve had reported to me that one of my plugins (Simple Twitter Link – but I’m sure this equally occur in others) is generating the error “cannot yet handle MBCS in html_entity_decode”. In fact, it generates it about 200 times.

The problem? Well, it’s a bug in version 4 of PHP, so there’s not much I can do about it (sorry!). It’s fixed in PHP 5, though.

One suggested solution is to force your server to use PHP 5 – many have version 5 installed, but just not set as the default. To do this simply put AddType application/x-httpd-php5 .php in the first line of your .htaccess file.

I use html_entity_decode for the post title. At the moment I do this whether you ask for the title or not – I’ll make a change for the future to ONLY do this if requested. That way you can omit the title to prevent this error from occurring. This will definitely also affect Simple Social Bookmarks and Simple Facebook Link.

Related posts:
  1. WordPress Social Bookmarking Plugins updated! All 3 of my Wordpress social bookmarking plugins have now been updated – Simple Social Bookmarks, Simple Twitter Link and Simple Facebook Link. In fact,...
  2. WordPress Plugins Updated Today I have updated Simple Facebook Link and Simple Social Bookmarks. In both cases, I have added the ability to pass an API key, user...
  3. Simple Social Bookmarks – WordPress Plugin This new WordPress plugin will display icons for various popular social bookmarks sites on your posts and/or pages. You can view more details and download...

Share with Delicious Share with Digg Share with Facebook Share with LinkedIn Share with MySpace Share with reddit Share with StumbleUpon Share with Twitter


Jul 09
6th

WordPress Plugins and File Fetching


A number of my recent plugins have provided a facility to read files from other sites. However, as I posted about, errors were being reported by some users and so I attempted a change in one such plugin to address this.

Unfortunately, that didn’t quite work as I intended. Kind of. In this case, I swapped to using a different file routine, but one which now only works with PHP 5. So I’ve now published a newer version of the same plugin using another new method, and one that should now be compatible with PHP 4.

The problem here is that there are security implications with reading files externally, so there is a way for hosts to turn this ability off.

My new plugin, I suspect, doesn’t actually resolve this and there isn’t a great amount I can do about this – if your host has decided to prevent you from reading external files then, well, you’re stuffed. My host doesn’t, which might explain why I didn’t recognise the problem at first.

The file system I’ve used now, however, should allow you to specify local file names – at least that way files hosted by yourself should be readable. I’ve not tested it though, so feel free to provide feedback.

I’m now going to upgrade my other plugins with the same code process.

Related posts:
  1. URL file-access is disabled Many of my plugins read from XML or RSS feeds. In these cases, I read the files using the PHP file_get_contents() command. However, if you...
  2. Change logs for WordPress plugins The standard readme.txt for WordPress plugins has been updated to allow for changelogs. This is excellent news and has happened at just the right time...
  3. Getting Help for my Wordpress Plugins If you'd like some help with any of my WordPress plugins then I'm more than happy to help. But please read this post to find...

Share with Delicious Share with Digg Share with Facebook Share with LinkedIn Share with MySpace Share with reddit Share with StumbleUpon Share with Twitter


Apr 09
21st

URL file-access is disabled


Many of my plugins read from XML or RSS feeds. In these cases, I read the files using the PHP file_get_contents() command. However, if you get the following error…

Warning: file_get_contents(): URL file-access is disabled in the server configuration

..then this means that your PHP is not configured to allow this command.

If you can, edit your php.ini file (usually located in /etc/php.ini) and make sure this line is in it:

allow_url_fopen = On

If you can’t edit php.ini, you can try the following…

If you don’t have one already, create a file called .htaccess in your root folder. Now add the following line:

php_value allow_url_fopen on

If that doesn’t work then, well, that’s probably down to restrictions by your host.

Related posts:
  1. WordPress Plugins and File Fetching A number of my recent plugins have provided a facility to read files from other sites. However, as I posted about, errors were being reported...
  2. Simple Feed List – WordPress Plugin updated! Version 1.2 of the Simple Feed List plugin has been launched! This update includes two essential changes.. Some people were finding that their web site’s...

Share with Delicious Share with Digg Share with Facebook Share with LinkedIn Share with MySpace Share with reddit Share with StumbleUpon Share with Twitter


Mar 09
11th

Optimize and Backup your MySQL databases


At the moment I’m juggling 3 MySQL databases. It could very easily be more.

I usually use phpMyAdmin for backing them up but restrictions on port forwarding has meant I can’t do this whilst at work1. So, I wrote myself a script to do this. And optimize the tables as well.

An extract of the script is below… mine allows me to choose the database and compression type and then populates the appropriate database fields (username, password, etc) but for generic usage purposes, the script below should be fine for other people to use and build upon.

if ($compression=="None") {$comp_cmd=""; $comp_ext="sql";}
if ($compression=="Gzip") {$comp_cmd=" | gzip"; $comp_ext="gzip";}
if ($compression=="Zip") {$comp_cmd=" | zip"; $comp_ext="zip";}    

mysql_connect($host,$user,$password);
mysql_select_db($database);
$query="SHOW TABLE STATUS FROM ".$database;
$result=mysql_query($query);
$num=mysql_numrows($result);
$compressed=0;
$i=0;
while ($i < $num) {
   $table=mysql_result($result,$i,"Name");
   $gain=mysql_result($result,$i,"Data_free");
   if ($gain!=0) {
       if ($compressed==0) {echo "<br/>Compressing tables...<br/><br/>\n";}
       echo "Table ".$table." - ".$gain." bytes gained<br>\n";
       $query="OPTIMIZE TABLE ".$table;
       $optimise=mysql_query($query);
       $compressed=$compressed+$gain;
   }
   $i++;
}
if ($compressed!=0) {
   echo "<br/>".$compressed." bytes gained in total<br/>";
} else {
   echo "<br/>No tables were optimised.<br/>";
}
$backupFile = "backup/".$name."_".date("Ymd").'.'.$comp_ext;
$command = "mysqldump --opt --extended-insert --complete-insert --hex-blob
--host=".$host." --user=".$user." --password='".$password."' ".$database.
$comp_cmd." > $backupFile";
exec($command, $ret_arr, $ret_code);
if ($ret_code==0) {
   echo "<br/>Database backed up: <a href=\"".$backupFile."\">download</a>.\n";
} else {
   echo "<br/>The database could not be backed up - the return code was ".
$ret_code.".\n";
};

Before running the above, you need to populate the following fields…

$database – your MySQL database
$user – your MySQL username
$password – your MySQL password
$host – your MySQL host name
$name – used to name your backup
$compression – this is the type of compression you wish to apply and should be either None, Zip or Gzip.

When run any tables that require optimizing will be, well, optimized and the details output. Finally a backup is made of the database and a link displayed so that you can download it.

Downloads are placed in a folder named /download, so make sure you add write permissions for this folder. The filename will be xxx_yymmdd, where xxx is the name you specified in $name and yymmdd is the date. Obviously the extension will be based on the type of compression you requested.

Whilst trying to write this code I came across various scripts and resources which did something similar but often didn’t work (grrr) for one reason or another. In particular, often the backup files are create empty if you have the MySQLdump parameters wrong. One thing you might spot that I’ve worked around – and here’s my tip for the day – is that I’ve placed single quotes around the password. This was because one of my passwords had an ampersand in it and, well, MySQLdump doesn’t like it.

Enjoy, play and let me know how you get on!

  1. and I have a tendency to forget if I leave it until the evening at home []
Related posts:
  1. Finding the number of users online I often wondered how sites detected the number of users online. After some digging I’ll admit to be no closer to the answer. The problem...
  2. Tonights Site Issues You may have noticed the site go offline earlier. You may have even seen it appear as a default, and empty, WordPress blog. Or you...

Share with Delicious Share with Digg Share with Facebook Share with LinkedIn Share with MySpace Share with reddit Share with StumbleUpon Share with Twitter


Nov 08
21st

Reading RSS with PHP


After using the JavaScript only and generally pretty poor facility within Feedburner to embed RSS feeds onto a website, I set about an alternative solutions.

Thankfully, there are a number available. However, many offer little embedding options and I wanted something that gave me full control. This narrowed it down to 2 free downloadable scripts. However, as much as I tried I couldn’t get them to work properly.

Everything went well until it came to a link in my item description – then the less than/greater than signs would mysteriously disappear. Bizarrely, if I used the option to run it from the authors script from their site, it worked. So I can only assume it’s a configuration on my server. However, I’ve not been able to work out what it is.

Now, PHP has built in XML parsing options and this is what these scripts were using – and I’m guessing the configuration option in question was to do with that. So I gave up and decided to write my own alternative. It doesn’t use XML parsing but simply reads the whole file in and extracts the details I need – in this case title, description and date. The code is below – pass the RSS feed into it by assigning it to the variable $rss_feed.

$array=file_get_contents($rss_feed);
$i=0;
while ($i!=1) {
$item_start=strpos($array,"<item>");
if ($item_start===false) {
$i=1;
} else {
$item_end=strpos($array,"</item>");
$item_length=$item_end+7-$item_start;
$item_strip=substr($array,$item_start,$item_length);
$title_start=strpos($item_strip,"<title>");
$title_end=strpos($item_strip,"</title>");
$title_length=$title_end+8-$title_start;
$title=substr($item_strip, $title_start+7, $title_length-15);
$pubdate_start=strpos($item_strip,"<pubDate>");
$pubdate_end=strpos($item_strip,"</pubDate>");
$pubdate_length=$pubdate_end+10-$pubdate_start;
$pubdate=date("jS F Y",strtotime(substr($item_strip,
$pubdate_start+9, $pubdate_length-19)));
$description_start=strpos($item_strip,"<description>");
$description_end=strpos($item_strip,"</description>");
$description_length=$description_end+14-$description_start;
$description=substr($item_strip, $description_start+13,
$description_length-27);
$array=substr($array,$item_end+7);
}
}

I’ve left some of the code expanded – for example there is no need for each field to be calculating and storing the end position as this could simply be placed within the length calculation. However, so you can see what I’m doing I’ve left it as it is.

So, during each iteration you will have 3 fields available for you to use, and probably display. They are $title, $pubdate and $description. $pubdate is converted into a more readable format using the date command, but the parameters can be easily changed to format it in another way.

Related posts:
  1. Reading Picasa captions in PHP Ok, it’s going to get technical. Although I’ve recently bought Photoshop Elements, Picasa used to be my photo browser of choice (in fact it still...
  2. Add Twitter links to your WordPress posts Want an easier way to add links to Twitter user pages? Here’s a quick solution. Add the following code to your functions.php file within your...

Share with Delicious Share with Digg Share with Facebook Share with LinkedIn Share with MySpace Share with reddit Share with StumbleUpon Share with Twitter
77 queries in 3.684 seconds.