Page 1 of 1

Serious Problem

Posted: Sat Apr 27, 2002 11:39 am
by dethron
Hi All,
I have a really big problem :)) As you have seen below.....

/*********A PART OF AN ARRAY ($arr)*****************/
..........................
[490] =>

[491] => <marquee border="0" height="18"

[492] => style="font-family: Helvetica ; font-weight:bold; background-color:#000000; color:white; font-size:11px"

[493] => behavior="scroll" align="middle" scrollamount="4">
.....................

/***************************************************/

Now I want to find specific element of this array, let say $arr[491] then I want to use following code,

/****************THE CODE*********************/
$key="<marquee border=\"0\" height=\"18\"";
for ($i=475;$i<515;$i++){
if($arr[i]==$key){ //Problem here.PH.Line3
$start=$i-7;
$i=515;
}
}
echo $start;
if($start){
for ($k=$start;$k<$start+295;$k++){
echo $arr[$k];
}
}

/*********************************************/

But some how, in line 3 $key doesn't match with $arr[491]. I observed this code 4 times. Seriousness of this problem is that I can not see any problem. Please I need someone to help me :)) Thanx to All

Re: Serious Problem

Posted: Sat Apr 27, 2002 12:30 pm
by twigletmac
buyukcer wrote:Hi All,
if($arr==$key){ //Problem here.PH.Line3


From a quick glance at the code, I think you might want to change

Code: Select all

if($arr&#1111;i] == $key) &#123;
to

Code: Select all

if($arr&#1111;$i] == $key) {
note the dollar sign in front of the 'i'.

Mac

....

Posted: Sat Apr 27, 2002 12:49 pm
by dethron
Yes you are right twigletmac, I forgot $ sign. But, the problem does not be solved. Still the equality,if($arr[$i]==$key), can not be satisfied....

Re: Serious Problem

Posted: Sat Apr 27, 2002 2:27 pm
by twigletmac
OK. Looking a bit closer, perhaps the problem is this line:

Code: Select all

$i = 515;
in the first for loop.

Basically all that loop does is set $i to 475 to start and then you set $i to 515 in the loop. This means that you are only ever testing $arr[475] == $key in the if loop which you know isn't true. Take out the $i=515 bit and the for loop will run more than once.

Mac

Posted: Sat Apr 27, 2002 2:41 pm
by dethron
But as you see in my code $i=515 is a part of if statement. Actually I wanted to use the line "$i=515" as "break". When I found the right line, I want to end th for loop. So if equality is satisfied $i takes the value 515 and for loop ends. However the real problem is in "if statement". Am I right? Thanks your time, please continue with your suggestions.

Posted: Sat Apr 27, 2002 2:49 pm
by twigletmac
buyukcer wrote:But as you see in my code $i=515 is a part of if statement.
Oops sorry bit sleepy and not paying enough attention.

If I run the following code:

Code: Select all

<?php

$arr = array(
    490 => '',
    491 => '<marquee border="0" height="18"', 
    492 => 'style="font-family: Helvetica ; font-weight:bold; background-color:#000000; color:white; font-size:11px"',
    493 => 'behavior="scroll" align="middle" scrollamount="4"'
);

$key='<marquee border="0" height="18"'; 
for ($i=475;$i<515;$i++)&#123; 
	if($arr&#1111;$i]==$key)&#123;
		$start=$i-7; 
		$i=515; 
	&#125; 
&#125; 
echo $start; 
if($start)&#123; 
	for ($k=$start;$k<$start+295;$k++)&#123; 
		echo $arr&#1111;$k]; 
	&#125; 
&#125; 

?>
I get this output:
my browser window wrote:484<marquee border="0" height="18"style="font-family: Helvetica ; font-weight:bold; background-color:#000000; color:white; font-size:11px"behavior="scroll" align="middle" scrollamount="4"
Isn't that what you're looking for?

Mac

Posted: Sat Apr 27, 2002 3:08 pm
by dethron
yes this is a good way of debugging but I have already done this, and result is obvious. I modified the loop like that

/*******new for loop*****/
for($i=475;$i<515;$i++){
if($arr[$i]==$key){
$start=$i-7;
$i=515;
}
else{
echo $i."<br>";
}
/********end************/

as you may guess i saw numbers from 475 to 514. I know something wrong with $key, so you right, but I wonder what is the problem of this string? Why $arr[491] never be equal to $key. I used echo $arr[491] and echo $key lines. And then they gave similar outputs. But indeed, they are not. I should find a way to examine their similarity? :roll:

Posted: Sat Apr 27, 2002 3:11 pm
by twigletmac
Sorry editted post after actually trying the code myself :) . Check out the code above.

Mac

String Parsing costs my last 3 or 4 hours

Posted: Sat Apr 27, 2002 3:40 pm
by dethron
Finally i found the problem, following assignment is fatal :D

Code: Select all

$key="<marquee border="0" height="18"";
However I'm still thirsty to answer :cry:
The actual problem is stem from string parsing. Since our string includes <, ,",1,8 the normal string assignment does not work. Now the question is obvious, What is the all rules for escape charcters.(php manual is not a good guide on this issue)

Thanx All,