Bug #52198 [Com]: strpos not working correctly
| From: | anon at anon dot com | Date: | Thu, 01 Jul 2010 01:31:14 +0000 |
| Subject: | Bug #52198 [Com]: strpos not working correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152001@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52198&edit=1
ID: 52198
Comment by: anon at anon dot com
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:
This is hilarious.
Previous Comments:
------------------------------------------------------------------------
[2010-06-29 11:12:35] rasmus@php.net
Would you please do what I asked 3 times already? Make it possible for
us to
reproduce your problem. That means showing us your exact inputs.
eg.
function j2wp_change_single_url( $j2wp_post, $lnk_pos )
{
global $CON,
$wpdb;
echo "j2wp_post = ".print_r($j2wp_post,1); // ADD THIS
echo "lnk_pos = ".$lnk_pos."\n"; // ADD THIS
$j2wp_wp_tb_prefix = get_option('j2wp_wp_tb_prefix');
$j2wp_joomla_tb_prefix = get_option('j2wp_joomla_tb_prefix');
echo "j2wp_wp_tb_prefix = $j2wp_wp_tb_prefix\n"; // ADD THIS
echo "j2wp_joomla_tb_prefix = $j2wp_joomla_tb_prefix\n"; // ADD THIS
...
And do a View-Source for the results so you don't get tricked by
browser
encodings.
Or better yet, make a little standalone case that includes this function
and
pass the variables into it that is causing it to fail and put that up
somewhere.
I can assure you that strpos does not change based on any sort of
hosting
environment issues. Your problem is entirely in your code or in the
data you
are passing into it.
------------------------------------------------------------------------
[2010-06-29 09:15:01] christian dot gnoth at arcor dot de
Hello,
that a standalone case is working or not is not the point here. Again I
do not doubt that the strpos function is working in a different
environment and test case.
In the whole script it is working on different positions where I use
this strpos function!!!
But here in this working process it is not working !!!
$strpos_ret = strpos( $post_lnk_string, 'article&id=');
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' . $post_lnk_string .
'
:' . $strpos_ret . ':<br />';
In this two lines you can see that the variable $post_lnk_string is
passed to the strpos function. The echo after that shows the variable
content and the return of the strpos function. The standalone test case
is there !!!
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"
::
shows the content of the variable with which it was passed to the strpos
function. Also it shows the return_value of the strpos function.
So, to tell it is not a PHP problem is not true - if the same script
with the same data is running in your environment without this problem -
then I think it is a problem of the environment which the webhoster
provides.
------------------------------------------------------------------------
[2010-06-28 21:19:16] rasmus@php.net
That function is not a standalone test case. It references global
variables and
calls other functions like get_option, j2wp_extract_number,
j2wp_get_post_url_for_id and a bunch of others. Why in the world can't
you make a
simplified standalone case that hardcodes some of these to whatever you
have them
set to and makes it very clear what you are passing to this function?
Until you do that, you will get no help from here. I assure you that
this is not
a PHP bug.
------------------------------------------------------------------------
[2010-06-28 21:12:19] christian dot gnoth at arcor dot de
as I wrote I offered you the complete source as zip file and the mysql
dump.
then the whole php function is printed in this report.
I changed the script and simplyfied the else tree:
function j2wp_change_single_url( $j2wp_post, $lnk_pos )
{
global $CON,
$wpdb;
$j2wp_wp_tb_prefix = get_option('j2wp_wp_tb_prefix');
$j2wp_joomla_tb_prefix = get_option('j2wp_joomla_tb_prefix');
$permalink = false;
// $lnk_pos ---> pos at href=" string in post_content
// $post_lnk_end ---> pos at last " in link string of
post_content
// $post_lnk_string ---> contains the whole link string inkl. " at
the end
$post_lnk_end = strpos( $j2wp_post['post_content'], '"',
$lnk_pos + 7);
$post_lnk_string = substr( $j2wp_post['post_content'], $lnk_pos,
$post_lnk_end - $lnk_pos + 1 );
if ( !(strrpos( $post_lnk_string, '/') === false) )
$pos_lnk_last_slash = strrpos( $post_lnk_string, '/');
$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) )
{
$pos_article_id += 11;
$article_id = j2wp_extract_number( substr( $post_lnk_string,
$pos_srticle_id ) );
$url_post_id = j2wp_get_post_url_for_id( $article_id );
$permalink = get_permalink( $url_post_id );
}
else
{
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' . $post_lnk_string .
'<br />';
but still the output is the same. It still goes in the else tree.
please take the time to look ofver the source which is provided here -
it already shows the complete php function.
------------------------------------------------------------------------
[2010-06-28 19:59:03] rasmus@php.net
Sorry, but you have PHP configured to parse files in that directory, so
nobody
can download your source code. Try it for yourself.
And what simplifying your problem will do is show you that it isn't a
strpos
issue. Start with your complex example that isn't doing what you
expect.
Simplify it a little bit and see if it is still "broken". Keep doing
that until
it starts working and you will have found your bug.
So far you have done nothing but waste our time. You refuse to provide
a simple
reproducing script and you also have not provided a way to get your
complicated
reproducing script.
------------------------------------------------------------------------
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