Jump to content


Photo

Basic query - find a string within a string?


  • Please log in to reply
1 reply to this topic

#1 totallytech

totallytech

    Member

  • Members
  • PipPip
  • 17 posts

Posted 07 February 2013 - 05:40 PM

Hey Guys,

I'm trying to run some code to say if the string "ims_image" is found do this.... else do that...

I'm trying this:

<?php
$current = $_SERVER['REQUEST_URI'];
$mystring = 'ims_image';
$pos = strpos($mystring, $current);
echo "Search For " . $mystring . " within " . $current . "..... " . $pos;

if ($pos !== false) { ?>
        echo '<div class="sidebar1">';
        get_sidebar('gallery-left');
        echo '</div>';
} else { }     
?> 

Currently its failing - the echo output should say: Search For ims_image within /demo/ims_image/iwp-12-15-0011..... then either true or false but its blank.... just says Search For ims_image within /demo/ims_image/iwp-12-15-0011.....

Am I using the wrong method of searching the string?

#2 totallytech

totallytech

    Member

  • Members
  • PipPip
  • 17 posts

Posted 07 February 2013 - 05:49 PM

Ugh, scrub that... I was using it wrong!

$pos = strpos($mystring, $current);

should be

$pos = strpos($current, $mystring);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com