itay Posted July 22, 2010 Share Posted July 22, 2010 when I run my script. it goes through the IF statement, and executes what's inside the brackets. then it proceed to the ELSE and execute it as well!! how can it be? this is the snippet from my code: if (preg_match_all("/$regexp/siU", $f04_extrapages_a, $matches, PREG_SET_ORDER)) { echo '<font color="gold">if!</font>'; foreach($matches as $match) { # $match[2] = link address $seqlink=$match[2]; } if (preg_match('/next_button_inactive/',$f04_extrapages_a)) { if ($log==1) echo date('h:i:s') . "End of results.<br />"; return '1'; } else { $seqlink="http://www.411.com".$seqlink; if ($log==1) echo date('h:i:s') . "sequel link: $seqlink<br />"; return $seqlink; } } else { echo '<font color="gold">else!</font>'; if ($log==1) echo date('h:i:s') . "<strong><font color='red'>F**K! <I>preg_match_all(\"/$regexp/siU\", $f04_extrapages_a, $matches, PREG_SET_ORDER)</i> HAS FAILED!</font></strong>"; return '0'; } here is a snippet from the output I get: if!07:17:44sequel link: http://www.411.com/business?key=hair+salon&page=2&t=0bf2bc88f69d4364883a782fe9dfd06c&where=11103 else!07:17:44F**K! preg_match_all("/]*href=("??)([^" >]*?)\1[^>]*>(.*)<\/a>/siU", , Array, PREG_SET_ORDER) HAS FAILED!07:17:44: Quote Link to comment https://forums.phpfreaks.com/topic/208538-script-executes-the-if-and-the-else-how-can-that-happend/ Share on other sites More sharing options...
DaiLaughing Posted July 22, 2010 Share Posted July 22, 2010 I can't see it either. I'm not saying I would have done it that way but I can't see the problem. Have you tried deleting various bits until the problem goes away? Or delete everything except the two gold echoes and then add stuff back in. Quote Link to comment https://forums.phpfreaks.com/topic/208538-script-executes-the-if-and-the-else-how-can-that-happend/#findComment-1089558 Share on other sites More sharing options...
itay Posted July 22, 2010 Author Share Posted July 22, 2010 i've disabled the RETURN command at the end of inner ELSE, and it fixed the issue! weird... // return $seqlink; but still no good, because I need that RETURN. (this code snippet is a part of a function) Quote Link to comment https://forums.phpfreaks.com/topic/208538-script-executes-the-if-and-the-else-how-can-that-happend/#findComment-1089561 Share on other sites More sharing options...
gwolgamott Posted July 22, 2010 Share Posted July 22, 2010 Try a if(pregmatch()) - elseif(!pregmatch()) statement just to see if that works. There must be some logic that I do not see either that must have an issue. The return messing it up is odd. Maybe something with that variable? Quote Link to comment https://forums.phpfreaks.com/topic/208538-script-executes-the-if-and-the-else-how-can-that-happend/#findComment-1089583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.