What does "strpos() expects parameter 3 to be integer, string given" mean?

I made a little change to this code and added: || $url,‘onepage’ and now get this error. Can’t find anything om Google to help me. What does it mean?

<?php $url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];if (strpos($url,'yourcart' || $url,'onepage') !== false): ?>

The strpos() function accepts two or three parameters, the third one being optional.

  1. is “haystack”, the thing to search in.
  2. is “needle”, the thing to find.
  3. is an offset, where to start searching, it must be an integer.

You have the string “onepage” as parameter 3.

What are you hoping to achieve by adding that code into strpos() ? It doesn’t seem to make sense on the face of it.

2 Likes

Not without seeing what follows the conditional.

All that can be deduced is that for whatever reason, the intention is some code will run if the URL has either “yourcart” or “onepage” in it.

It might, but I don’t think it would, that strpos would consider
("yourcart" || "onepage") as a string.
But I’m sure separate strpos tests for each would work.

I barely know any php. It was to display links on those pages only. I just made a whole new strpos for each one like this.

<?php $url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];if (strpos($url,'yourcart') !== false): ?> <div style="text-align:center"> <p> <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>frequently-asked-questions.html');" style="font-size:10px"><?php echo $this->__('Help') ?></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>conditions.html');" style="font-size:10px"><?php echo $this->__('Terms & Conditions') ?></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>privacy-policy-popup.html');" style="font-size:10px"><?php echo $this->__('Privacy Policy') ?></a></p> <div class="angels-copy"><p><a href="<?php echo $this->getUrl('') ?>" style="text-decoration:none;color:#797979">&#169; <?php echo Mage::getStoreConfig('general/store_information/name',Mage::app()->getStore()->getId()); ?>, <?php echo Mage::getStoreConfig('general/store_information/address'); ?></a> </p> </div> </div> <?php endif;?> <?php $urlonepage = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];if (strpos($urlonepage,'onepage') !== false): ?> <div style="text-align:center"> <p> <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>frequently-asked-questions.html');" style="font-size:10px"><?php echo $this->__('Help') ?></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>conditions.html');" style="font-size:10px"><?php echo $this->__('Terms & Conditions') ?></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="javascript:poptastic('<?php echo $this->getUrl('') ?>privacy-policy-popup.html');" style="font-size:10px"><?php echo $this->__('Privacy Policy') ?></a></p> <div class="angels-copy"><p><a href="<?php echo $this->getUrl('') ?>" style="text-decoration:none;color:#797979">&#169; <?php echo Mage::getStoreConfig('general/store_information/name',Mage::app()->getStore()->getId()); ?>, <?php echo Mage::getStoreConfig('general/store_information/address'); ?></a> </p> </div> </div> <?php endif;?>

I very much appreciate the help.

That looks like it will work.
And if this is the only place you will ever need to do this it should be OK enough.

But instead of

if (this) {
output stuff
}
if (that) {
output stuff
}

If “output stuff” is exactly the same, I would do

if ((this) || (that)) {
output stuff
}

instead. A matter of easier to read conditionals vs. less duplication

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.