Determine extension that PHP function belongs to? - php

Sometime I find a function in the PHP manual that I want to use, but when I try to use it - it's undefined.
How can I consistently find which extension a function belongs to? It doesn't seem to be written in the PHP manual.
For example, mb_strlen belongs to the mbstring extension.
Given A, how do I consistently find B?

It's in the manual. See the sidebar on the left:
Multibyte String
Multibyte String Functions
Click either one of those and then go to the introduction to read about the extension. Then check out the Installing/Configuring page.

Related

Terminology question on "dereferencing"?

In PHP, the following code is valid
$a=array(0);$a[0];
but that one is invalid:
array(0)[0]
What is the terminology corresponding to that behaviour? (has it anything to do with "dereferencing"?)
What is the motivation behind such a behaviour (besides user spite :-P)
I am looking for the general terminology, not necessarily the terminology associated with PHP.
(Other example: in MATLAB, the following is valid:
s = size(M)
s(0)
but that is invalid:
size(M)(0)
In both PHP and MATLAB, adding parenthesis does not help, i.e., (array(0))[0] and (size(M))(0) are both invalid)
That's called Array dereferencing, and will become available in PHP 5.4 (which is currently in alpha)
Note (thanks Gordon) : what you are asking for, with array()1, is not possible even in PHP 5.4 -- but it'll work for functions.
A couple of sources :
RFC - Function Array Dereferencing
Features in PHP trunk: Array dereferencing, when it was unsure whether there would be a PHP 5.4 or a PHP 6
And, last but not least, the (currently last) news on php.net : PHP 5.4 alpha1 released
Quoting that last news :
Here is an incomplete list of changes: - Added: Traits language
construct - Added: Array dereferencing support - Added:
DTrace support - Improved: Improved Zend Engine memory usage and
performance - Moved: ext/sqlite moved to pecl (sqlite3 support is
still built-in)
1.array() is not a function, even if it looks like one -- it's actually what PHP calls a language construct ; and those don't behave like functions.
This is called "array dereferencing" and it will be available for use in PHP5.4.

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.

Can you use conditionals in IMAP_SEARCH from the PHP IMAP library?

I haven't been able to find anything while exploring the code and searching for documentation. Has anyone been able to achieve this?
http://php.net/manual/en/function.imap-search.php
No, you can't. (Hard to believe, right?)
PHP uses Mark Crispin's c-client library under the hood to do its IMAP work. In the c-client library, there is a deprecated method mail_criteria in mail.c that translates an IMAP search string to a c-client search program. mail_criteria has been deprecated for the past 8 years or so and, as such, was never updated to support the IMAP4 search syntax. So search terms like OR that weren't present in IMAP2 never got support in the mail_criteria function. Here's all the terms it supports starting with an 'O':
case 'O': /* possible OLD, ON */
if (!strcmp (criterion+1,"LD")) f = pgm->old = T;
else if (!strcmp (criterion+1,"N"))
f = mail_criteria_date (&pgm->on,&r);
break;
OR isn't on that list. So even though the c-client supports OR in its SEARCHPGM structs, it doesn't parse OR in the deprecated mail_criteria function.
And PHP still uses mail_criteria to parse search queries. In 2011. So until either the c-client library un-deprecates mail_criteria and makes it IMAP4-compliant or PHP writes its own IMAP search parser, you are stuck with whatever IMAP2 supported. Which doesn't include OR.

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.

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

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.

Categories