Edit report at http://bugs.php.net/bug.php?id=52198&edit=1
ID: 52198 Updated by: paj...@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: 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. Previous Comments: ------------------------------------------------------------------------ [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] ras...@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. ------------------------------------------------------------------------ [2010-06-28 17:08:11] christian dot gnoth at arcor dot de as you can see the strpos function works also in my script it returns the position 40, but only in the static passing of the strings. In the work process - the function is called for each url - somehow the variables are not processed correctly (maybe some problem in the memory areas???). The content of the variables is shwon correctly through the echo construct, but the content is not processed correctly by the strpos function. ------------------------------------------------------------------------ [2010-06-28 16:08:43] ras...@php.net The test script I provided doesn't work? ------------------------------------------------------------------------ [2010-06-28 16:07:30] christian dot gnoth at arcor dot de here now the output where I do echo the strpos return: Joomla To Wordpress Migration - Status Messages The following links must be changed manually: Post ID: 105 link: href="webcasts/llpa/llpa.html" :: Post ID: 105 link: href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97" :40: Post ID: 105 link: href="webcasts/llpa/llpa.html" Post ID: 106 link: href="component/search/ihda.html?ordering=&searchphrase=all" :: Post ID: 106 link: href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97" :40: Post ID: 106 link: href="component/search/ihda.html?ordering=&searchphrase=all" 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" Post ID: 287 link: href="index.php?option=com_content&view=article&id=356:qaa-fannie-mae-and-freddie-mac&catid=39:news&Itemid=70" :: Post ID: 287 link: href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97" :40: Post ID: 287 link: href="index.php?option=com_content&view=article&id=356:qaa-fannie-mae-and-freddie-mac&catid=39:news&Itemid=70" Post ID: 293 link: href="index.php?option=com_content&view=article&id=331:fed-funds-recap-the-fed-oil-and-you&catid=44:dailyupdate&Itemid=96" :: Post ID: 293 link: href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97" :40: here the changed script: // $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 { as you can see, PHP does not find the string in the variable and the working process!!! ------------------------------------------------------------------------ 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