Edit report at http://bugs.php.net/bug.php?id=52198&edit=1
ID: 52198
Updated by: rasmus@php.net
Reported by: christian dot gnoth at arcor dot de
Summary: strpos not working correctly
Status: Bogus
Type: Bug
Package: Strings related
Operating System: Linux
PHP Version: 5.2.13
New Comment:
No, you need to take the time to simplify your case into a standalone
test that
proves your point instead of asking us to weed through a lot of code.
There is
absolutely nothing wrong with the strpos function, so the exercise of
producing a
standalone test will be enlightening for you. You can choose not to
believe me, I
suppose, that is entirely up to you.
Previous Comments:
------------------------------------------------------------------------
[2010-06-28 19:10:28] christian dot gnoth at arcor dot de
of what use is it to proove something what is working???
That there is no difference is not true!!!
if I pass a constant string always each function call it is different
than to pass variable which content is with each call different. Means
the memory for the static string remains always equal with each call,
but the memory area of the variable is always differnet - in place (I
think with each call the variable is allocated again, or?) and in
content.
So please take the time and look through the code I provided - you can
see clearly that the output is generated at the end of the else tree in
which the PHP interpreter should never go!!!
The output is generated of the variable $post_lnk_string
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' . $post_lnk_string .
'<br />';
the if:
if ( !(strpos( $post_lnk_string, 'article&id=') === false) )
should not allow that to happen!!!!!
and as you can see in the output:
Post ID: 107 link:
href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"
::
Post ID: 107 link:
href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"
:40:
Post ID: 107 link:
href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"
from the source code:
$strpos_ret = strpos( $post_lnk_string, 'article&id=');
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' . $post_lnk_string .
'
:' . $strpos_ret . ':<br />';
$strpos_ret = strpos(
'href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"',
'article&id=');
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' .
'href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"'
. ' :' . $strpos_ret . ':<br />';
// urls with structure:
href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"
// if ( $pos_article_id = strpos( $post_lnk_string, 'article&id=') )
if ( !(strpos( $post_lnk_string, 'article&id=') === false) )
the problem is not with the if, but with the strpos function !!!!
Please take the time and look through this code examples and the
generated output!!!
------------------------------------------------------------------------
[2010-06-28 18:58:44] rasmus@php.net
The test script I showed you used variables, not static strings.
My guess (since I can't decipher your messy code) is that your POST data
is
probably getting parsed or filtered and the contents isn't what you
think it is.
Your & might actually be & so the strpos isn't going to match. Look
for
issues along those lines. strpos works fine, so the longer you keep
blaming
strpos the longer it will take you to find your bug.
------------------------------------------------------------------------
[2010-06-28 18:26:24] pajoye@php.net
If you are experiencing a problem with strpos and variables, then please
provide a script similar to:
$haystack = "some content";
$needle = "content";
if (strpos($haystack, $needle) === false)) {
echo "not found\n";
} else {
echo "found\n";
}
Everything else is irrelevant.
However, as Rasmus said, there is no difference in strpos if you pass a
static variable or a string.
------------------------------------------------------------------------
[2010-06-28 18:20:08] christian dot gnoth at arcor dot de
Hello,
that 5 lines are working - I do not doubt. That is not the problem here.
Again, strpos is working with static strings passed, but with
variables.
That is a fact as you can see it. The output is generated at the only
position in the else tree!!!! So with strpos working correctly it should
never go there for that string!!!
If you like, I can send you the MySQL dump file and the php script.
------------------------------------------------------------------------
[2010-06-28 17:15:54] rasmus@php.net
Your bug is elsewhere. There is no difference between passing a static
string and
passing a variable. The only difference happens if the contents of the
variable
is different. Write a 5-line script that reproduces the problem and you
will see.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=52198
--
Edit this bug report at http://bugs.php.net/bug.php?id=52198&edit=1