Quantcast

Forums | MacLife

You are not logged in.

#1 2009-09-09 1:05 am

b_dubb
loch whatchamacallit
From: chapel hill, nc
Registered: 2002-11-19
Posts: 510
Website

stristr() question

i want to search a string for '.swf'.  so ...

Code:

if ( stristr($string,'.swf') === TRUE ) { echo "WOOT"; }

however ... this is not working.  what i'm doing EXACTLY IS ...

Code:

$flash_code = "<object width="550" height="400"><param name="movie" value="somefilename.swf"><embed src="somefilename.swf" width="550" height="400"></embed></object>";
$flash_code_array = explode('"',$flash_code);
$count_flash_code_array = count($flash_code);

for ( $i = 0; $i < $count_flash_code_array; $i++ ) {
    if ( stristr($flash_code_array[$i],"swf") === TRUE ) {
        $flash_code_array[$i] = $flash_file;
    } 
}

$flash_code = implode('"',$flash_code_array);
echo "    <div id=\"flash_header\">$flash_code</div>\r\n";

the goal here is to find the chunk of the EMBED code that refers to the '.swf' and replace that with the '/path/filename' value.  it seems i can't get the stristr() statement to evaluate as true

here's a snapshot of what the exploded EMBED string looks like as an array

Code:

Array
(
    [0] => <object width=
    [1] => 550
    [2] =>  height=
    [3] => 400
    [4] => ><param name=
    [5] => movie
    [6] =>  value=
    [7] => somefilename.swf
    [8] => ><embed src=
    [9] => somefilename.swf
    [10] =>  width=
    [11] => 550
    [12] =>  height=
    [13] => 400
    [14] => ></embed></object>
)

** using PHP 5.2.5

pre-emptive thanks

b

Last edited by b_dubb (2009-09-09 1:07 am)


"The Fates lead he who will; he who won't, they drag." - Seneca

Offline

 

#2 2009-09-09 9:59 am

jerwin
Sophist
From: The Garden of Pure Ideology
Registered: 2003-01-01
Posts: 7035

Re: stristr() question

I don't know PHP... but

Return Values

Returns the matched substring. If needle is not found, returns FALSE.

function stristr

So, presumably, you'd test for nonfalse values.

Code:

if ( stristr($string,'.swf') != FALSE) { echo "WOOT"; }

Last edited by jerwin (2009-09-09 10:04 am)


Some subjects actually enjoy pain, and withhold information they might otherwise have divulged in order to be punished.
Central Intelligence Agency. (1983). Human Resource Exploitation Training Manual

Offline

 

#3 2009-09-09 11:38 am

b_dubb
loch whatchamacallit
From: chapel hill, nc
Registered: 2002-11-19
Posts: 510
Website

Re: stristr() question

i think i smurfed up the first example.  what i'm doing in my actual code is (trying) to test for TRUE.  so it would look more like

Code:

if ( stristr($string,'.swf') === TRUE) { echo "WOOT"; }

i think?


"The Fates lead he who will; he who won't, they drag." - Seneca

Offline

 

#4 2009-09-09 12:45 pm

jerwin
Sophist
From: The Garden of Pure Ideology
Registered: 2003-01-01
Posts: 7035

Re: stristr() question

if I'm reading the docs correctly, it never returns TRUE. It either returns the substring, or FALSE. So, you must test for nonfalse returns. Thus '!= FALSE'.


Some subjects actually enjoy pain, and withhold information they might otherwise have divulged in order to be punished.
Central Intelligence Agency. (1983). Human Resource Exploitation Training Manual

Offline

 

#5 2009-09-09 1:26 pm

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50393
Website

Re: stristr() question

jerwin wrote:

if I'm reading the docs correctly, it never returns TRUE. It either returns the substring, or FALSE. So, you must test for nonfalse returns. Thus '!= FALSE'.

That's the way I read the manual as well.

Code:

<?php
  $email = 'USER@EXAMPLE.com';
  echo stristr($email, 'e'); // outputs ER@EXAMPLE.com
  echo stristr($email, 'e', true); // As of PHP 5.3.0, outputs US
?>

makes that pretty clear.


In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor

Offline

 

#6 2009-09-09 1:30 pm

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50393
Website

Re: stristr() question

btw - you want to make sure the array variable ends in .swf.
Otherwise it could theoretically trigger off of something that doesn't but happend to have the four character .swf string in it.


In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson