How do you split up a filename in PHP, and insert code?
Posted: Mon Mar 06, 2017 10:27 am
We are looking at using srcset in our website, writing it ourselves.
Is it best to store each version name in it’s own database field? image, image475, image768 and so on?
Or a better way I was thinking (which is similar perhaps to Wordpress) is to dynamically write on page what numbers we want.
So :
My question is, how do I break up the filename from the variable (in case we did a .jpeg or a .png), and concatenate in that file extension?
So we take $row->image, split up the name and extension into two variables. So it reads a little more like this:
Is it best to store each version name in it’s own database field? image, image475, image768 and so on?
Or a better way I was thinking (which is similar perhaps to Wordpress) is to dynamically write on page what numbers we want.
So :
Code: Select all
<img srcset="/images/pages/$row->image”.475.”.jpg 475w,
/images/pages/$row->image”.768.”jpg 768w,
/images/pages/$row->image”.475.”.jpg 1920w"
sizes="(max-width: 475px) 475px,
(max-width: 768px) 768px,
(max-width: 1920px) 1920px"
src="/images/pages/25644881item-phone-name.jpg" alt='photo name here'>
$row->image”.475.”
So we take $row->image, split up the name and extension into two variables. So it reads a little more like this:
Code: Select all
<img srcset="/images/pages/$imagename"."475"."$imageextension"." 475w,....