I want call a BEFORE in PHP
my code so far:
<?php
$folder_path = $cdnurl . 'assets/' . $pid . '/';
// Loop from 2 to 5
for ($i = 2; i <= 6; $i++) {
if(@fopen($folder_path . $i . '/large.jpg',"r")){
?>
<li><a id="<?php echo $i;?>" href="<?php echo $i;?>/large.jpg"><?php echo $i;?></a></li>
<?php } else {
break;
}
}?>
EDIT
I edited the code above as it is already nested with IF and ELSE. I want it to echo. something like
<ul>
<li>2</li>
<li>before</li>
<li>3</li>
<li>4</li>
</ul>
That’s just a basic if():
Though, since you’re starting your for loop at 2, this would only ever output “before 3” once, when i=2. So it’d be more efficient to do:
instead and save yourself the useless if() check.
given your code sample update:
Note the use of
is_readable(). It’s easier to check for a file’s existence/readability using that than trying open the file. As well, note the HEREDOC used to output the list element, rather than a regular echo.