Edit report at http://bugs.php.net/bug.php?id=52198&edit=1
ID: 52198 Comment by: christian dot gnoth at arcor dot de 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: 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. Previous Comments: ------------------------------------------------------------------------ [2010-06-28 19:59:03] ras...@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. ------------------------------------------------------------------------ [2010-06-28 19:52:40] christian dot gnoth at arcor dot de what will be enlightening to me if I know that the strpos function is working in a simple script and with a static string passed, but not in big script with different function calls? What I have if I proove the strpos is working, but in the that case not? I provided the source code here. In the directory you will find the .php files which you can download - I see in the browser a direcotry list. f you want I can provide a MySQL dump and the php scripts as .zip file. But the source code is above of the whole function. ------------------------------------------------------------------------ [2010-06-28 19:21:29] ras...@php.net By the way, even if I was inclined to look through your code, you haven't provided it. The http://joomla-wp.it-gnoth.de/wp-content/plugins/joomla2wp/ link is useless since it doesn't serve up a visible version of the scripts there. ------------------------------------------------------------------------ [2010-06-28 19:13:54] ras...@php.net 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. ------------------------------------------------------------------------ [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!!! ------------------------------------------------------------------------ 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