Searching for a substring inside an array in php - php

Hi I would like to know if there is a good algorithm to the search of a substring inside an array that is inside another array,
I have something like:
Array(
[0] => Array(
[0] => img src="1" />
[1] => img src="2" alt="" class="logo i-dd-logo" />
[2] => img src="3" alt="" />
[3] => img src="4" width="21" height="21" alt="" class="i-twitter-xs" />
[4] => img src="myTarget" width="21" height="21" alt="" class="i-rss" />
[5] => <img class="offerimage" id="product-image" src="6" title="" alt=""/>
[6] => <img class="offerimage" id="product-image" src="7" title="" alt=""/>
[7] => <img class="offerimage" id="product-image" src="8" title="" alt=""/>
[8] => <img src="9" width="16" height="16" />
)
[1] => Array(
[0] => src="1"
[1] => src="a" alt="" class="logo i-dd-logo"
[2] => src="b" alt=""
)
)
What I want to do is to know the position of target, for example [0][4] but it's not always the same
What I'm doing now is a while inside another while and checking whith strpos for the substring, but maybe there is a better way to do this, any suggestions?
Thanks for everything
Updated code:
$i=-1;
foreach($img as$outterKey=>$outter) {
foreach($outter as $innerKey=>$inner){
$pos = strpos($img[$outterKey][$innerKey],"myTarget");
if (!$pos === false) {
$i=$outterKey;$j=$innerKey;
break 2;
}
}
}

Umm, maybe like:
foreach($outsideArray as $outterKey=>$outter) {
foreach($outter as $innerKey=>$inner){
if(substr_count ($inner , $needle)) {
echo $outterKey . " and " . $innerKey;
}
}
}
EDIT: Scalable, I noticed in your comments you want it scalable. How about recursive?
function arraySearch($array) {
foreach($array as $key=>$item){
if(is_array($item)
return arraySearch($item);
elseif(substr_count ($item , $needle)
return $key;
}
}

try this code here you got the complete posistion of your string.
here $find is your substring. $data is your array.
$find = "<img src='4' width='21' height='21' alt=' class='i-twitter-xs' />";
foreach ($data as $out_key => $out_value)
{
if(is_array($out_value))
{
if(in_array($find, $out_value))
{
$out_pos = array_search($out_value, $data);
$inn_pos =array_search($find, $out_value);
}
}
}
echo $data[$out_pos][$inn_pos];

Related

PHP get image url from html-string using regular expression

I'm trying to get all images urls from a html-string with php.
Both from img-tags and from inline css (background-image)
<?php
$html = '
<div style="background-image : url(https://exampel.com/media/logo.svg);"></div>
<img src="https://exampel.com/media/my-photo.jpg" />
<div style="background-image:url('https://exampel.com/media/icon.png');"></div>
';
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>|background-image[ ]?:[ ]?url\([ ]?[\']?["]?(.*?\.(?:png|jpg|jpeg|gif|svg))/i', $html, $image);
echo('<pre>'.print_r($image, true).'</pre>');
?>
The output from this is:
Array
(
[0] => background-image : url(https://exampel.com/media/logo.svg
[src] =>
[1] =>
[2] => https://exampel.com/media/logo.svg
)
Prefered output would be:
Array
(
[0] => https://exampel.com/media/logo.svg
[1] => https://exampel.com/media/my-photo.jpg
[2] => https://exampel.com/media/icon.png
)
I'm missing something here but I cant figure out what
Use preg_match_all() and rearrange your result:
<?php
$html = <<<EOT
<div style="background-image : url(https://exampel.com/media/logo.svg);"></div>
<img src="https://exampel.com/media/my-photo.jpg" />
<div style="background-image:url('https://exampel.com/media/icon.png');"></div>
EOT;
preg_match_all(
'/<img.+src=[\'"](.+?)[\'"].*>|background-image ?: ?url\([\'" ]?(.*?\.(?:png|jpg|jpeg|gif|svg))/i',
$html,
$matches,
PREG_SET_ORDER
);
$image = [];
foreach ($matches as $set) {
unset($set[0]);
foreach ($set as $url) {
if ($url) {
$image[] = $url;
}
}
}
echo '<pre>' . print_r($image, true) . '</pre>' . PHP_EOL;

Foreach not showing all items in multidimensional array

This is my first question in a long time, any help is greatly appreciated!
I've got one database storing vehicles and one database storing their images. I am using an INNER JOIN to grab a list of vehicles and their images. After the database query, I put the return into an array; so 2 arrays in 1 array:
return array($vehicles, $vehicle_images);
When I do a print_r I get the correct return:
<?php print_r($your_listings[0]); ?>
<br />
<?php print_r($your_listings[1]); ?>
Returns:
Array
(
[0] => Array
(
[vehicle_id] => 35
[vehicle_type] => jeep
[vehicle_vin] => 6969
[owner_email] => user#user.com
[vehicle_make] => Jeep
[vehicle_year] => 2008
[vehicle_model] => cherokee
)
[1] => Array
(
[vehicle_id] => 36
[vehicle_type] => motorcycle
[vehicle_vin] => 1234
[owner_email] => user#user.com
[vehicle_make] => honda
[vehicle_year] => 2018
[vehicle_model] => random
)
[2] => Array
(
[vehicle_id] => 39
[vehicle_type] => atv
[vehicle_vin] => 3215
[owner_email] => user#user.com
[vehicle_make] => Yamaha
[vehicle_year] => 1990
[vehicle_model] => OHYEA
)
)
Array
(
[0] => Array
(
[vehicle_id] => 35
[image_display] => placeholder
)
[1] => Array
(
[vehicle_id] => 36
[image_display] => /new/images/vehicles/users/42/image.jpg
)
[2] => Array
(
[vehicle_id] => 36
[image_display] => /new/images/vehicles/users/42/vehicle1.jpg
)
[3] => Array
(
[vehicle_id] => 35
[image_display] => /new/images/vehicles/users/42/vehicle.jpg
)
[4] => Array
(
[vehicle_id] => 39
[image_display] => placeholder
)
)
Now when I do a foreach (including bootstrap 4 styling), it only shows 2 vehicles instead of 3; the 2 vehicles it shows appear to be showing exactly as I want them:
<div class="container-fluid">
<div class="row no-gutters">
<?php
$your_listings = owner_listings($_SESSION['user']);
if (!($your_listings[0])) {
echo '<div class="col-sm"><div class="alert alert-danger" role="alert"><i class="fas fa-exclamation"></i> You do not have any listings active at this time.</div></div>';
}
else {
foreach ($your_listings as $i => $item) {
$make = $your_listings[0][$i]['vehicle_make'];
$model = $your_listings[0][$i]['vehicle_model'];
$year = $your_listings[0][$i]['vehicle_year'];
$vehicle = $your_listings[0][$i]['vehicle_id'];
$image = $your_listings[1][$i]['image_display'];
if ($image != 'placeholder') {
echo '<div class="col-sm"><div class="card" style="width: 18rem;">
<h5 class="card-title text-center font-weight-bold">'.$year.' '.$make.' '.$model.'</h5>
<img class="card-img-top" src="'.$image.'" alt="'.$year.' '.$make.' '.$model.'">
<div class="card-body">
Edit
</div>
</div></div>';
}
else {
if ($your_listings[0][$i]['vehicle_type'] == 'atv') {
$image = '/new/images/vehicles/types/atv.png';
}
elseif ($your_listings[0][$i]['vehicle_type'] == 'jeep') {
$image = '/new/images/vehicles/types/jeep.png';
}
elseif ($your_listings[0][$i]['vehicle_type'] == 'motorcycle') {
$image = '/new/images/vehicles/types/motorchycle.png';
}
echo '<div class="col-sm"><div class="card" style="width: 18rem;">
<h5 class="card-title text-center font-weight-bold">'.$year.' '.$make.' '.$model.'</h5>
<img class="card-img-top" src="'.$image.'" alt="'.$year.' '.$make.' '.$model.'">
<div class="card-body">
Edit
</div>
</div></div>';
}
}
}
?>
</div>
</div>
Have I just been staring at this too long? What am I doing wrong? Any help is appreciated.
Thanks!
You are looping original array which has two arrays as you said. What you want is to loop through only first element of your_listings array to get three vehicles
if (!($your_listings[0])) {
echo '<div class="col-sm"><div class="alert alert-danger" role="alert"><i class="fas fa-exclamation"></i> You do not have any listings active at this time.</div></div>';
}
else {
foreach ($your_listings as $i => $item) { // should be foreach ($your_listings[0] as $i => $item) {
$make = $item['vehicle_make'];
$model = $item['vehicle_model'];
Give a try to this answer...
<div class="container-fluid">
<div class="row no-gutters">
<?php
$your_listings = owner_listings($_SESSION['user']);
if (!($your_listings[0]))
{
echo '<div class="col-sm"><div class="alert alert-danger" role="alert"><i class="fas fa-exclamation"></i> You do not have any listings active at this time.</div></div>';
}
else
{
$newarray = array();
foreach($your_listings[0] as $i => $item)
{
$newarray[$item["vehicle_id"]] = $item["image_display"];
}
foreach ($your_listings[0] as $i => $item)
{
$make = $item['vehicle_make'];
$model = $item['vehicle_model'];
$year = $item['vehicle_year'];
$vehicle = $item['vehicle_id'];
$image = $newarray[$vehicle];
if ($image != 'placeholder')
{
echo '<div class="col-sm"><div class="card" style="width: 18rem;">
<h5 class="card-title text-center font-weight-bold">'.$year.' '.$make.' '.$model.'</h5>
<img class="card-img-top" src="'.$image.'" alt="'.$year.' '.$make.' '.$model.'">
<div class="card-body">
Edit
</div>
</div></div>';
}
else
{
if ($item['vehicle_type'] == 'atv') {
$image = '/new/images/vehicles/types/atv.png';
}
elseif ($item['vehicle_type'] == 'jeep') {
$image = '/new/images/vehicles/types/jeep.png';
}
elseif ($item['vehicle_type'] == 'motorcycle') {
$image = '/new/images/vehicles/types/motorchycle.png';
}
echo '<div class="col-sm"><div class="card" style="width: 18rem;">
<h5 class="card-title text-center font-weight-bold">'.$year.' '.$make.' '.$model.'</h5>
<img class="card-img-top" src="'.$image.'" alt="'.$year.' '.$make.' '.$model.'">
<div class="card-body">
Edit
</div>
</div></div>';
}
}
}
?>
</div>
</div>

How I echo this kind of array in php?

I do have an array something like below:
[images] => Array
(
[0] => Array
(
[id] => 1
[path] => ../images/properties/1/1447053991.jpg
)
[1] => Array
(
[id] => 3
[path] => ../images/properties/1/1447054231.jpg
)
[2] => Array
(
[id] => 4
[path] => ../images/properties/1/1447054666.jpg
)
[3] => Array
(
[id] => 17
[path] => ../images/properties/1/1447141341.jpg
)
)
When I need to echo this array, I want to add different HTML for first key of this array and also different HTML for other keys.
This is how I tried it:
foreach($property['images'] as $image) {
//echo '<pre>',print_r($image).'</pre>';
if ($image['id'] != '') {
$html .= " <a href='".$image['path']."' class='image-wrap' title='' rel='prettyPhoto'>\n";
$html .= " <img src='".$image['path']."' alt=''/>\n";
$html .= " <span class='zoom-icon'></span>\n";
$html .= " </a>\n";
} else {
$html .= " <a href='".$image['path']."' title='1' rel='prettyPhoto[group]'></a>\n";
}
}
But its not working for me. Hope somebody may help me out.
If I am not wrong your foreach is printing values as expected and you want the first index to print out something different then others..
foreach($property['images'] as $index => $image) {
//echo '<pre>',print_r($image).'</pre>';
if ($index == 0) {
// do stuff for the first index
} else {
// do stuff for other indexes
}
}
since you want to display first image as image and the rest in anchor tag try this.use a counter to identify first and the rest.there can be two cases.
case 1: when your index does not start with 0.
$property=array('images' => Array
(
'0' => Array
(
'id' => 1,
'path' => '../images/properties/1/1447053991.jpg'
),
'1' => Array
(
'id' => 3,
'path' =>'../images/properties/1/1447054231.jpg'
)
)
);
$html="";
$counter=0;
foreach($property['images'] as $image) {
if ($image['id'] != '') {
if($counter == 0){
$html .= " <img src='".$image['path']."' alt=''/>\n";
$counter++;
}else{
$html .= " <a href='".$image['path']."' class='image-wrap' title='' rel='prettyPhoto'>".$image['id']."\n";
$html .= " <span class='zoom-icon'></span>\n";
$html .= " </a>\n";
}
} else {
$html .= " <a href='".$image['path']."' title='1' rel='prettyPhoto'group''></a>\n";
}
}
echo $html;
?>
case 2: when index starts from 0.
foreach($property['images'] as $key=>$image) {
if ($image['id'] != '') {
if($key == 0){
$html .= " <img src='".$image['path']."' alt=''/>\n";
}else{
$html .= " <a href='".$image['path']."' class='image-wrap' title='' rel='prettyPhoto'>".$image['id']."\n";
$html .= " <span class='zoom-icon'></span>\n";
$html .= " </a>\n";
}
} else {
$html .= " <a href='".$image['path']."' title='1' rel='prettyPhoto'group''></a>\n";
}
}

How to get normal src of an coded image like this in php?

Hi there I works with simple php parser to save imgs form external server...So I want to get an normal src of an picture
but it seem below img elements has an unusuall src ...
Is there anyway to turn this code to normal src or at least first save it in my server?
Note: text in src is too long...more than 170000 chars...I removed most of them to insert here to show you...
<img style="display: block; margin-left: auto; margin-right: auto;" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAZAAA/+4ADkFkb2JlAGTAAAAAAf/bAIQAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQICAgICAgICAgICAwMDAwMDAwMDAwEBAQEBAQECAQECAgIBAgIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD/8AAEQgBZQJ2AwERAAIRAQMRAf/EANcAAAAFBQEAAAAAAAAAAAAAAAIDBAgJAQUGBwoAAQAABgMBAQAAAAAAAAAAAAACAwQFBgcAAQgJChAAAQMCBAQEAwUFBQQFCQQLAQIDBBEFACESBjFBEwdRYSIIcRQJgZGhMhWxwdFCI/DhUjMW8WJyJJKistIXgkNTdLQldTcYwo1J+AH8U2v8uqLpH6v5jprx0gEfAaySD8RiOkWfmihfp9w/igf0u9f//Z" alt="">
Copy all of the src text after base64, and use php's base64_decode function to decode it. Once there you can write it to a jpg file if you want.
<?php
echo base64_encode(file_get_contents("../images/folder16.gif"))
?>
You can use PHP function to get the image coded.
See this working example :
<?php
$img = base64_encode(file_get_contents("https://www.google.co.in/images/srpr/logo11w.png"));
echo "<img src='data:image/gif;base64,".$img."' />";
?>
Follow the following steps
<?php
// [1] Prepare your page HTML content
$html = '<img src="data:image/png;base64,image_[1]_valid_base_64_encoded_string">';
$html .= '<img src="data:image/gif;base64,image_[2]_valid_base_64_encoded_string">';
$html .= '<img src="data:image/jpeg;base64,image_[3]_valid_base_64_encoded_string">';
$html .= '<img src="data:image/jpg;base64,image_[4]_valid_base_64_encoded_string">';
// [2] Get all src attributes
$xpath = new DOMXPath(#DOMDocument::loadHTML($html));
$src = $xpath->evaluate("//img/#src");
// [3] Loop src attributes and push image info to $images arary
$images = array();
foreach ($src as $attr)
{
$data = explode('/', $attr->value);
$data = str_replace(';', ',', $data[1]);
list($extension, $type, $encoded_string) = explode(',', $data);
// push to images array
$images[] = array(
'extension' => strtolower($extension),
'image_base64' => $encoded_string,
);
}
// results
echo '<pre>';
print_r($images);
echo '</pre>';
// [4] Move images to directory
// #file_put_contents("path/to/dir/image_name.$extension", base64_decode($encoded_string));
// print_r($images) output
Array
(
[0] => Array
(
[extension] => png
[image_base64] => image_[1]_valid_base_64_encoded_string
)
[1] => Array
(
[extension] => gif
[image_base64] => image_[2]_valid_base_64_encoded_string
)
[2] => Array
(
[extension] => jpeg
[image_base64] => image_[3]_valid_base_64_encoded_string
)
[3] => Array
(
[extension] => jpg
[image_base64] => image_[4]_valid_base_64_encoded_string
)
)

Creating Next/Previous pagination links

I am working on a portfolio site and have all projects in array, I have created a project template page that uses a GET variable to set the current project and load appropriate content into page. I am trying to add links at the bottom that link to the next and previous project but cannot figure out the correct way to write the link
Here is what the array looks like:
$projects = array();
$projects["Beeston-Residence"] = array(
"name" => "Beeston House",
"heroClass" => "hero-beeston",
"mainImg" => BASE_URL ."images/beeston_main.jpg",
"previewImg" => BASE_URL ."images/beeston_preview.jpg",
"year" => "2014",
"yearClass" => "twenty14",
"location" => "Brisbane, Australia",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/beeston_detail1.jpg",
"detailTwo" => BASE_URL ."images/beeston_detail2.jpg",
"detailThree" => BASE_URL ."images/beeston_detail3.jpg",
"detailFour" => BASE_URL ."images/beeston_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum detail 1",
"detailTwoSum" => "lorem ipsum detail 2",
"detailThreeSum" => "lorem ipsum detail 3",
"detailFourSum" => "Lorem ipsum detail 4",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/beeston_mat1.jpg",BASE_URL ."images/beeston_mat2.jpg",BASE_URL ."images/beeston_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
$projects["Book-Tower-Residence"] = array(
"name" => "Book Tower House",
"heroClass" => "hero-bookTower",
"mainImg" => BASE_URL ."images/bookTower_main.jpg",
"previewImg" => BASE_URL ."images/bookTower_preview.jpg",
"year" => "2012",
"yearClass" => "twenty12",
"location" => "London, United Kingdom",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/bookTower_detail1.jpg",
"detailTwo" => BASE_URL ."images/bookTower_detail2.jpg",
"detailThree" => BASE_URL ."images/bookTower_detail3.jpg",
"detailFour" => BASE_URL ."images/bookTower_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum",
"detailTwoSum" => "lorem ipsum",
"detailThreeSum" => "lorem ipsum",
"detailFourSum" => "Lorem ipsum",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/bookTower_mat1.jpg",BASE_URL ."images/bookTower_mat2.jpg",BASE_URL ."images/bookTower_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
$projects["1917-Bungalow"] = array(
"name" => "1917 Bungalow",
"heroClass" => "hero-bungalow",
"mainImg" => BASE_URL ."images/bungalow_main.jpg",
"previewImg" => BASE_URL ."images/bungalow_preview.jpg",
"year" => "2013",
"yearClass" => "twenty13",
"location" => "Autstin, Texas",
"photographer" => "Rachel Cruz",
"detailOne" => BASE_URL ."images/bungalow_detail1.jpg",
"detailTwo" => BASE_URL ."images/bungalow_detail2.jpg",
"detailThree" => BASE_URL ."images/bungalow_detail3.jpg",
"detailFour" => BASE_URL ."images/bungalow_detail4.jpg",
"description" => "lorem ipsum and shit",
"detailOneSum" => "lorem ipsum",
"detailTwoSum" => "lorem ipsum",
"detailThreeSum" => "lorem ipsum",
"detailFourSum" => "Lorem ipsum",
"materials" => array("matOne","matTwo","matThree"),
"materialImg" => array(BASE_URL ."images/bungalow_mat1.jpg",BASE_URL ."images/bungalow_mat2.jpg",BASE_URL ."images/bungalow_mat3.jpg"),
"testamonialImg" => BASE_URL ."images/client.jpg",
"testamonial" => "Cabin Is Great!"
);
etc... The array has 15 projects in total
The project template The projects get filtered into is set up like this:
<?php
require_once("../includes/config.php");
require_once(ROOT_PATH . "includes/projectInfo.php");
$project_id = $_GET["id"];
$project = $projects[$project_id];
include (ROOT_PATH . "includes/header-project-page.php");
?>
<section class="l-col-group project-intro">
<h2 class="project-title"><?php echo $project["name"]; ?> </h2>
<aside class="project-info">
<ul class="project-brief">
<li class="pb-heading">STATUS </li>
<li class="pb-info">Complete <?php echo $project["year"];?></li>
<li class="pb-heading">LOCATION</li>
<li class="pb-info"><?php echo $project["location"];?></li>
<li class="pb-heading">PHOTOGRAPHER</li>
<li class="pb-info"><?php echo $project["photographer"];?></li>
</ul>
</aside>
<p class="project-summary">
<?php echo $project["description"];?>
</p>
</section>
<section>
<figure class="l-col-group">
<figcaption class= "left">
<h3>VISION</h3>
<p><?php echo $project["detailOneSum"];?></p>
</figcaption>
<img class="project-detail-img right" src="<?php echo $project["detailOne"];?>" alt="">
</figure>
<figure class="l-col-group">
<figcaption class="right">
<h3>DESIGN</h3>
<p><?php echo $project["detailTwoSum"];?></p>
</figcaption>
<img class="project-detail-img left" src="<?php echo $project["detailTwo"];?>" alt="">
</figure>
<figure class="l-col-group left">
<figcaption class="left">
<h3>DEVELOPMENT</h3>
<p><?php echo $project["detailThreeSum"];?></p>
</figcaption>
<img class="project-detail-img right" src="<?php echo $project["detailThree"];?>" alt="">
</figure>
<figure class="l-col-group">
<figcaption class="right">
<h3>TEAM</h3>
<p><?php echo $project["detailFourSum"];?></p>
</figcaption>
<img class="project-detail-img left" src="<?php echo $project["detailFour"];?>" alt="">
</figure>
</section>
<section class="testamonial">
<img class="testamonial-image" src="<?php echo BASE_URL; ?>images/testamonial.png" alt="testamonial">
<h3 class="testamonial-client">DAVID WALSH</h3>
<p class="testamonial-quote">Cabin surpassed went above and beyond my wildest dreams! Customer service at its best.</p>
</section>
include (ROOT_PATH . "includes/contact.php");
include (ROOT_PATH . "includes/footer.php");
?>
I have had luck retrieving the current projects position in the array by using the following:
<?php $key = array_search($project, $projects);
$offset = array_search($key, array_keys($projects));
$next = $offset + 1;
$prev = $offset - 1;
?>
But am having trouble on figuring out how to use this information to create a link to the next project in the array
I was trying something like this but do not know what to put as the link
<?php if ($prev > 0): ?>
<a style ="color:black" href="">Previous</a>
<?php endif; ?>
<?php
Thank you in advance for the help.
CHEERS.
It's probably better and simpler to pass indexes and not ids:
// get project id
$lst_ids = array_keys($project);
$i = !empty($_GET["i"]) ? $_GET["i"] : 0;
$project_id = $lst_ids[$i];
// show previous and next links, as applicable
$l = count($projects); // should give 15
$html = '';
if ($i) {
$i_prev = $i - 1;
$label = "← Previous";
$html .= "<a href='?i=$i_prev'>$label</a>";
}
if ($i < ($l - 1)) {
$i_next = $i + 1;
$label = "Next →";
$html .= " <a href='?i=$i_next'>$label</a>";
}
echo $html;
Or if you want to pass ids:
$l = count($projects); // should give 15
$lst_ids = array_keys($project);
$project_id = !empty($_GET["id"]) ? $_GET["id"] : NULL;
$index = $project_id ? array_search($project_id, $lst_ids) : 0;
$html = '';
if ($index) {
$id_prev = $lst_ids[$index - 1];
$label = "← Previous";
$html .= "<a href='?id=$id_prev'>$label</a>";
}
if ($index < ($l - 1)) {
$id_next = $lst_ids[$index + 1];
$label = "Next →";
$html .= " <a href='?id=$id_next'>$label</a>";
}
echo $html;

Categories