Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Welcome. I am trying to display the on-screen images from a folder. Everything works but in the beginning I display two empty pictures. Here is my code:
$fileObject = new DirectoryIterator('./images/');
foreach($fileObject as $file)
{
echo "<img src='".'./images/'.$file."' />";
}
Just skip . and ..:
$fileObject = new DirectoryIterator('./images/');
foreach($fileObject as $file)
{
if ($file->isDot()) continue;
echo "<img src='".'./images/'.$file->getFilename()."' />";
}
Also you probably want $file->getFilename() to get the filename.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to pass a simple php value to html but I cannot format it in the right way. How can I do this?
<?php
$html = '
<img src="'$val'.svg" alt="15"> //Does not work
';
$val = 5;
?>
You would try to format it this way:
<?php
$val = 5;
$html = "<img src='${val}.svg' alt='15'> ";
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i keep getting a break line at the beginning of the csv i've create, and in my array there isnt a break line.
here is my code:
$file = 'prueba.csv';
$filew1 = fopen($file, 'w');
foreach ($csv as $line) {
fwrite($filew1, $line . PHP_EOL);
}
fclose($filew1);
Yii::$app->response->SendFile($file);
and my out put is like this
i dont know why, i have try the str_replace() metod, still.
i have fix it, putting a ob_clean(); at the beginning of the method.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So, I get this assoc array structure :
pastebin.com/9nEGKsK0
How can I fetch the urls by 'foreach'?
Help.
You can try this:
<?php foreach($array['response']['items'] as $item) {
foreach($item['sizes'] as $size) {
echo $size['url'];
}
}
echo '<pre>';
print_r($array);
echo '</pre>';
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
$marks=array(
array(a1,a2,a3),
array(b1,b2,b3),
array(c1,c2,c3)
);
so i want this in foreach loop
example
echo "text-start".$marks[0]."text11".$marks[1]."text22".$marks[2]."text-end";
and result to be:
text-starta1text11a2text22a3text-end
text-startb1text11b2text22b3text-end
text-startc1text11c2text22c3text-end
i tried this but it show a1a2a3 b1b2b3
and i cant add text between them
for($r=0;$r<count($marks);$r++)
{
for($c=0;$c<count($marks[$r]);$c++)
{
echo $marks[$r][$c]."test";
}
echo "111<br>";
}
Basics...
foreach($marks as $marky_marks){
echo "text-start".$marky_marks[0]."text11".$marky_marks[1]."text22".$marky_marks[2]."text-end";
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My code is random but its does not print out the picture just the text. When I add the IMAGE tag. Its go all wrong. Where do I go wrong?
$plaatje[] = 'afbeelding1.jpg';
$plaatje[] = 'afbeelding2.jpg';
$plaatje[] = 'afbeelding3.jpg';
$plaatje[] = 'afbeelding4.jpg';
$nummer2 = mt_rand(1,4);
echo "$plaatje[$nummer2]";
Use array_rand() - Picks one or more random entries out of an array
echo $plaatje[array_rand($plaatje)];
With an image tag, something like:
<img src="<?php echo $plaatje[array_rand($plaatje)]; ?>" />
or
echo "<img src='".$plaatje[array_rand($plaatje)]."' />";
Here is the documentation
Although you should add the image tag to show where it goes wrong, your code already has a problem as array indices are 0-based.
So you would need:
$nummer2 = mt_rand(0,3);