News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Project:
Patchwork-UTF8 - UTF8 Support for PHP
January 27, 2012 @ 11:38:40

Nicolas Grekas has shared another tool that he's pulled out of his "Patchwork" framework to make it a stand-alone tool: the Patchwork-UTF8 helper that provides matching functions to those PHP already has for regular strings, but a little smarter to work with UTF8 correctly.

The PatchworkUtf8 class implements the quasi complete set of string functions that need UTF-8 grapheme clusters awareness. These functions are all static methods of the PatchworkUtf8 class. The best way to use them is to add a use PatchworkUtf8 as u; at the beginning of your files, then when UTF-8 awareness is required, prefix by u:: when calling them.

In the README for the tool he talks about the functions included in the current release that match PHP's string functions as well as some additional methods like "isUtf8", "bestFit" and "strtocasefold". It relies on the mbstring, iconv and intl extensions being installed, and if they aren't, it falls back to other functionality (list of those methods included).

0 comments voice your opinion now!
utf8 support string patchwork framework helper mbstring iconv intl


Evert Pot's Blog:
iconv_substr vs mbstring_substr
September 30, 2011 @ 11:03:20

Evert Pot came across an interesting performance issue as he was working through an application that needed to do some string substitutions - the difference between iconv_substr, mb_substr and substr.

While working on an application I ran across a huge bottleneck which I isolated down all the way to the use of the iconv_substr function. If you ever wonder which is better to use, [the benchmark code in the post[ should help your decision.

His results changed quite a bit from machine to machine (and OS/platform to OS/platform) but one statistic stood out on them all - the iconv_substr was slower than mb_substr method....by a lot in one case (about 2100000% slower).

0 comments voice your opinion now!
benchmark iconvsubstr mbstringsubstr substr substring


Ahmed Shreef's Blog:
iconv misunderstands UTF-16 strings with no BOM
August 27, 2010 @ 13:36:56

Ahmed Shreef has a recent post to his blog about an issue he had converting UTF-16 strings over to UTF-8 with the iconv functionality in PHP. Specifically, he ended up with "rubbish unreadable characters" after the conversion.

I had a problem last week with converting UTF-16 encoded strings to UTF-8 using PHP's iconv library on a Linux server. my code worked fine on my machine but the same code resulted in a rubbish unreadable characters on our production server.

In his example (a basic "Hello World" in Arabic) he notes that there's no byte order mark on the string and, because of this, the iconv feature tries to guess if it's big-endian or little-endian. This guessing varies from machine to machine resulting in the inconsistencies he saw. The solution is to define the "to" and "from" for the conversion manually rather than letting it just guess.

0 comments voice your opinion now!
byteordermark bom iconv utf16 utf8 convert


NETTUTS.com:
How to Create Blog Excerpts with PHP
July 23, 2010 @ 09:11:18

On NETTUTS.com today there's a tutorial (a screencast) that'll show you how to create excerpts for the posts in your blog. Their method could be applied to just about any PHP-based blog software out there since it uses base PHP functions and MySQL features.

Ever visited a blog, and noticed that each posting's overview only contained a hundred characters or so, which is then followed by '''? Ever wondered how to do that yourself? It's not quite as easy as you might think. What if character number 100 occurs in the middle of a word? Do you want to display half of a word on the page? Of course not. In this video tutorial, I'll show you how to compensate for this, as well as a host of other neat little things, like working with MySQL's LEFT() function, using PHP's strrpos, and substr, creating the beginning's of an actual blog, and more.

They show you how to use the MySQL LEFT() function, strrpos and substr to make creating these summary blocks of text simple.

0 comments voice your opinion now!
blog excerpt tutorial screencast mysql strrpos substr


Yannick's Blog:
mbstring vs iconv benchmarking
October 06, 2008 @ 12:50:20

Recently on his blog Yannick has done some benchmarking comparing mbstring and iconv in PHP 5.2.4 release.

Following up on my previous post about the differences between the mbstring and iconv international characters libraries (which resulted in a tentative conclusion that nobody knew anything about those differences), and particularly the comments by Nicola, we have combined forces (mostly efforts from Nicola, actually) to provide you with a little benchmarking, if that can help you decide.

His code for the test script is included (for you to gather your own results) and a full listing of his results comparing the effects of possible caching, running up to ten executions. You can download the text file that he ran the script on here.

0 comments voice your opinion now!
mbstring iconv benchmark php5 text file statistic


Hasin Hayder's Blog:
Web scrapping in a smart way, making a "Today in History" object in PHP
April 29, 2008 @ 10:27:41

Hasin Hayder has written up a quick tutorial for his blog that shows how to create your own "Today in History" page with details from Scopesys pulled with a little web scraping.

There are thousands of services available on web who are presenting interesting as well as education information which you can really integrate in your web page or make a nice widget and let others use them seamlessly with their content delivery platforms. In this article I am going to show you how you can make a nice Today-in-History widget with the help of the data provided in Scopesys.

He wisely recommends that you check one thing first about the content you're grabbing - the copyright it carries with it. This could get you into big trouble down the line depending on whose content it is. The actual script is pretty simple - he defines some constants as markers for where things start and stop in the HTML and then uses strpos to get the locations for his substr call to grab the segments.

0 comments voice your opinion now!
todayinhistory widget copyright scopesys constant define substr strpos


Dokeos Blog:
mbstring vs iconv
April 24, 2008 @ 11:18:08

In this post on the Dokeos blog, there's a comparison of the mbstring function and the iconv library as it pertains to their use on multi-byte strings.

I was wondering today why use mbstring rather than iconv in Dokeos, and honestly I didn't remember exactly why I had chosen mbstring in the past, but finding information about the *differences* between the two. [...] Searching a bit more, I found a PPT presentation from Carlos Hoyos on Google.

Essentially, it boils down to how the library is integrated - mbstring is bundled and iconv is pulled from an external source. So, if you're looking for maximum portability, he recommends mbstring.

0 comments voice your opinion now!
mbstring iconv multibyte character string compare internal external


Riff Blog:
Console encoding in PHP-GTK apps
November 20, 2006 @ 10:58:00

PHP-GTKers working in English-related applications, don't have a problem with debugging messages output to a console when debugging, but applications on a more international front have issues with their output. But help has been found in this new post on the Riff Blog - a method for correctly encoding PHP-GTK applications.

PHP scripts are typically stored under UTF-8 encoding to limit i18n headaches, while the console in which their output will be displayed is normally configured to some regional encoding, like IBM850 in Windows/XP French.

So we need a workaround...

He splits the process out into a few steps, each with its own explanation and code:

  • Builtin tools
  • Buffering
  • Flushing
  • PHP-GTK is not PHP for the Web
  • Auto-flushing
All wrapped up with a final solution - using the iconv functionality in combination with some output buffering to correctly display the message.

0 comments voice your opinion now!
phpgtk encoding output console i18n buffering iconv phpgtk encoding output console i18n buffering iconv


Christian Stocker's Blog:
Calling PHP function from XSLT vs. native XSLT functions benchmark
March 27, 2006 @ 06:55:47

One of the more underused thechnologies to come along these days is XSLT - that powerful langauge to style XML documents in a simple, "more correct" kind of way (seperation of data and layout). Most languages have support for this combination, including PHP - but what's the best way to combine PHP and XSLT? Christian Stocker took a look in this new post on the Bitflux blog.

After Rob's idea from yesterday about using XMLReader within XSLT I was wondering, how much of a slowdown calling PHP functions from XSLT is.

I wrote 4 different XSLT templates, which do a simple substring. One with the xslt function "substring", one with just calling the native PHP function "substr" and one with calling a user-defined function (which is also just calling "substr"). I called this 100 times (with one of those great recursive self-calling xslt-templates) and did call the "transformToXML" function a 100 times for each stylesheet. This means, we called the function 10'000 times for each benchmark run.

His bases the results off of a sample with no function call at all and, but running it through 100 times, came up with results that weren't all that surprising. In order of speed, the ranking (shortest time first) was: no call, xslt only, php native, and php userland. Using the PHP functions from inside of XSLT made the test quite a bit slower, but, as he notes, most users won't be running recursions of 100 each time they run a script.

1 comment voice your opinion now!
XSLT native functions user-defined substring substr XSLT native functions user-defined substring substr


Christian Stocker's Blog:
PHP 5, OS X, fink and iconv
January 06, 2006 @ 07:23:47

Christian Stocker has a quick new post with a solution for those Mac users out there that would like to use the iconv extension with fink.

If you want to get the iconv extension properly running with PHP 5 and fink on OS X, you need the following configure option

--with-iconv=/sw/

and then it should work.

Hope that helps others, too.

And, apparently, it does - given the one comment below it so far that has a positive response...

0 comments voice your opinion now!
fink iconv extension 5 OS X fink iconv extension 5 OS X



Community Events





Don't see your event here?
Let us know!


threedevsandamaybe opinion symfony2 community podcast framework refactor list language install interview testing developer api series introduction laravel unittest code release

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework