Bug #52198 [Com]: strpos not working correctly
| From: | christian dot gnoth at arcor dot de | Date: | Mon, 28 Jun 2010 16:20:11 +0000 |
| Subject: | Bug #52198 [Com]: strpos not working correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151934@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: 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:
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.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[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] rasmus@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!!!
------------------------------------------------------------------------
[2010-06-28 16:01:02] christian dot gnoth at arcor dot de
yes it does not work !!!
I get the result 40 if I put it directly as string in the function, but
in the variable it does not work.
Here the browser output:
Joomla To Wordpress Migration - Status Messages
The following links must be changed manually:
Post ID: 105 link: href="webcasts/llpa/llpa.html"
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: 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"
As you can see the Post ID 107 there is the string, but the output is
generated in the else tree of the if statement.
the whole script you can find under:
http://joomla-wp.it-gnoth.de/wp-content/plugins/joomla2wp/
here the script part:
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, '/');
// urls with structure:
href="index.php?option=com_content&view=article&id=9257:2009-fha-loan-limits&catid=52:fha&Itemid=97"
// if ( !(strpos( $post_lnk_string, 'article&id=') === false) )
if ( $pos_article_id = strpos( $post_lnk_string, 'article&id=') )
{
$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
{
// urls with structure: /82345-fha-loan-limits
// or
href="mortgagecenter/39-news/11548-focus-on-the-6500-tax-credit.html"
$itemid = j2wp_extract_number( substr( $post_lnk_string,
$pos_lnk_last_slash + 1 ) );
// itemid is there - look it joomla for title and creation,modified
date
if ( $itemid )
{
$url_post_id = j2wp_get_post_url_for_id( $itemid );
$permalink = get_permalink( $url_post_id );
}
else
{
// urls with structure: all other
// check
//
index.php?option=com_content&view=section&id=9&layout=blog&Itemid=64
//
index.php?option=com_content&view=category&id=49:credit-optimization&layout=blog&Itemid=78
// it is a category or .html or attachment file
$link_string = substr( $post_lnk_string, 7, strlen(
$post_lnk_string ) - 8);
$pos_lnk_last_slash = strrpos( $link_string, '/');
// check if is a category page
if ( !strpos($link_string, '.') )
{
$joomla_cat_title = NULL;
// determine the slug
if ( !$pos_lnk_last_slash )
{
$cat_slug = $link_string;
}
else
{
$cat_slug = substr( $link_string, strrpos( $link_string, '/')
+ 1);
}
j2wp_do_joomla_connect();
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' .
$post_lnk_string . ' cat_slug:' . $cat_slug . '<br />';
// Get the ID of a given category from Joomla
$query = 'SELECT id, title, alias FROM ' .
$j2wp_joomla_tb_prefix . 'categories WHERE alias = "' . $cat_slug . '"
';
echo $query . '<br />';
$result = mysql_query($query, $CON);
if ( !$result )
echo mysql_error();
while( $row = mysql_fetch_array($result) )
{
$joomla_cat_id = $row['id'];
$joomla_cat_title = $row['title'];
}
if ( $joomla_cat_title )
{
echo 'Cat: ' . $joomla_cat_title . '<br />';
$category_id = get_cat_ID( $joomla_cat_title );
// Get the URL of this category
$permalink = get_category_link( $category_id );
echo 'Cat_link: ' . $permalink . '<br />';
}
}
else
{
// check if there is a '.' inside the $last_string and not
.html - then it is an attachment
// strrpos($last_string, '.')
echo 'Post ID: ' . $j2wp_post['ID'] . ' link: ' .
$post_lnk_string . '<br />';
}
}
}
------------------------------------------------------------------------
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