My php can't find 'normalizer_normalize()' function, why? - php

How come I can't use normalizer function?
I am using it exactly as I should, ie: $var = normalizer_normalize($str);
I get php error: no such function!
Here is the code:
$headline= mysql_real_escape_string($_POST['headline']);
$ad_id_string=normalizer_normalize($headline);
Thanks

From the docs, normalizer_normalize was included in PHP as of version 5.3.0. Prior to that, it was available as a PECL extension. To build it as part of PHP, you'll need to install internationalization support.
If you need to provide your own equivalent to the Normalizer class, strtr() would be a good option. The only downside is that you will need to provide your own character strings to translate to / from.

Related

How can I make my open-source PHP app cross-server?

I have a PHP program using MySQL that I will be making open-source, including a simple installer, and I want to make it as easy to install on any server with PHP4 or 5 and MySQL 4 as possible.
I've included an installer to make it user-friendly, but I need to know what are the things I can do to make it most likely to install on every server.
I'll start: I've made sure to use full PHP tags (not short) like this <?php ?> and to make sure all variables are declared prior to using them, like so $nVar = (isset($_POST['nVar']) ? $_POST['nVar'] : NULL);.
What other best practices should be incorporated in a PHP app for the best cross-server compatability?
Just a few hints, from the top of my head
The class { __constructor } is deprecated.
Dont use GLOBAL
Use split and join
Watch out for file magic byte recognition functions
The get_class get_parent_class alphanumerical changed to accept camelcasing - use strtolower on returned value before comparing

Mb_encode_mimeheader in PHP

I'm trying to use mb_encode_mimeheader but I'm getting an error that it's an undefined function. Yet I believe it is part of native PHP.
Here is my code:
$encoded_subject = mb_encode_mimeheader('my foreign character string', 'UTF-8', 'B');
Is this function part of PHP that I need to extend or something? I've used this function before and never had any problems.
In order to use the mb_* functions, you need to ensure that the mbstring extension is available/compiled in. (It's not a default extension in terms of the "standard" install, but it is commonly available as a part of most well configured ISP offerings.)
See the Multibyte String installing/configuring section within the PHP manual for more information.
http://php.net/mbstring.installation
As mentioned there its not enabled by default. there is also mentioned, how to enable it.

Remove function alias in PHP

Is there a way to remove function alias in PHP?
I can rename my function but it would be nice to use name "fetch".
Problem:
I just tested the following code and it appears to work for me, but perhaps it is because I don't have the mysqli library installed. I would test it because it might be more contextual than your IDE will have you believe. It seems to be a method for mysqli, but it might not be a global function.
<?php
function fetch(){
echo 'Hello world!';
}
fetch();
No.
(Short of recompiling the PHP binary)
This is more of a function of the IDE than the actual language... Some IDEs may give you that ability... I don't even know if recompiling the PHP binary (as Alan Storm suggested) would help since sometimes the stuff is hardcoded into the IDE / use the PHP docs online
For completeness sake: Normally, no, this can not be done. However: this can be done using a PECL extension called "runkit".
Runkit is described as "For all those things you probably shouldn't have been doing anyway", and allows you to basically tear out the innards of PHP from within PHP itself. Replacing built-in functions, undefining constants, unloading classes - suddenly everything is possible. And you should really question what you are doing if you ever feel you need it - odds are what you are doing violates some principles that are there for very good reasons, you just don't know them yet. I've never found a situation where using Runkit was a genuinely Good Idea.
Oh, in order to remove built-in functions you'll specifically need to enable this capability in your php.ini
(have fun!)

php I need to write a json_encode function equivalent

I'm trying to use webspace provided by my university. They are currently using an outdated version of php, 5.1 I think. Anyway it doesn't have a json_encode function, however, I need a json_encode function (or equivalent) for my code to work.
So if anyone could explain to me the syntax for the return of the json_encode function or point me to a website that explains it nicely it'd be much appreciated.
Thanks
Don't reinvent the wheel: upgrade.php library.
http://pear.php.net/package/Services_JSON
Check here. It tells you to use require 'jsonwrapper.php'; at the start of your code in versions of PHP where json_encode is not available.

How to handle deprecated function in PHP

I'm new in this site. I want to ask about PHP programming. How do we can handle deprecated function in PHP. I want to redirect it to my new function. As we know, ereg function has been deprecated in PHP 5.3.0 and recommended to preg_match (posix to PCRE). But, when we wrote a lot of code with ereg function, do we have to change it manually? I want a solution like this.
function ereg($pattern, $string, &$array) { return preg_match('#'.$pattern.'#', $string, $array); }
The main problem is not the ereg function, but solution of handling deprecated function.
I've been searching in Google. Someone suggest to use override_function (using APD extension). But, this extension is hard to find (I need precompiled extension build for windows). Anyone can help me?
I'm sorry for my bad English. I hope you can understand.
The reason they tell you it is deprecated, and they don't remove it completely, is to give you time to update your code.
If you don't want to update your code, you can always just not upgrade your install of PHP. Or you can wait until a release of PHP is out were ereg() is removed completely, and use your above solution.
Other possible solutions include doing a search/replace for all ereg calls, and replacing it my_ereg, which could be the function you defined above.
Also:
if(!function_exists("ereg")){ .... }
Define the function inside of the if statement that checks if the function already exists. This will make the transition smoother.
But all in all, the purpose of deprecation is to give developers time to update their code and stop using all of the deprecated functions before they remove it completely from the code base.
I believe some call it 'Maintenance'.
You could always use the function_exists function.
if(!function_exists('ereg'))
{
function ereg($pattern, $string, &$array)
{
return preg_match('#'.$pattern.'#', $string, $array);
}
}
Using this method would allow it to work in all version as if it is deprecated but still able to be used it will use the function but once it has been removed from php it will be able to use your user defined function.

Categories