I am a little be a newbie in PHP (I have much experience in other programming languages like C# etc). So from experience in OOP, i am almost sure that this can be done also in PHP. Here is the question and problem. I am writting script thats going to export some html code. Here is example. I have folder on server with images of fruits. For example folder holds next images: strawberry.jpg, apple 1.jpg, apple 2.jpg, peach.jpg, bannana 1.jpg, bannana 2.jpg, pear.jpg. I am already written code thats working perfect but I want to be more advanced
<?php
$files = glob('./images/fruits/*.*');
foreach($files as $file) {
$filename = pathinfo($file);
$filepath1 = pathinfo($file, PATHINFO_BASENAME);
$filepath2 = "images/logotipi/fruits/".$filepath1;
echo '{slider <strong>'.$filename['filename'].'</strong>|blue}';
echo '<br>';
echo '{tip';
echo "<img src=\"".$filepath2."\">";
echo '}';
echo "<img src=\"".$filepath2."\" ";
echo 'width="100" height="100" />{/tip}';
echo '<br>';
}
?>
So what I want. As you see my output will be
{slider **strawberry**|blue}
{tip <img src="images/fruits/strawberry.jpg" />}<img src="images/fruits/strawberry.jpg" width="100" height="100" />{/tip}
{slider **apple 1**|blue}
{tip <img src="images/fruits/apple 1.jpg" />}<img src="images/fruits/apple 1.jpg" width="100" height="100" />{/tip}
{slider **apple 2**|blue}
{tip <img src="images/fruits/apple 2.jpg" />}<img src="images/fruits/apple 2.jpg" width="100" height="100" />{/tip}
...
And etc for each image. I want next i want to my output for each this slider that apple be in that slide for example. I want to my output be like this:
{slider **strawberry**|blue}
{tip <img src="images/fruits/strawberry.jpg" />}<img src="images/fruits/strawberry.jpg" width="100" height="100" />{/tip}
{slider **apple**|blue}
{tip <img src="images/fruits/apple 1.jpg" />}<img src="images/fruits/apple 1.jpg" width="100" height="100" />{/tip}
{tip <img src="images/fruits/apple 2.jpg" />}<img src="images/fruits/apple 2.jpg" width="100" height="100" />{/tip}
... So as you see I want to check names which are strings in string array of filenames. If i have more categories like apples, or bannanas, the names always end with number 1,2,3 etc. How can be done in php?