How do i go from this
width="200" height="300"
to this with php
width:200px; height:300px;
Basically i want to remove the quotes and equal signs and insert a semi colon after each attribute
How do i go from this
width="200" height="300"
to this with php
width:200px; height:300px;
Basically i want to remove the quotes and equal signs and insert a semi colon after each attribute
You can use regexp:
<?php
$html = 'width="200" height="300"';
$pattern = '/width="(\d+)"\s+height="(\d+)"/';
preg_match($pattern, $html, $matches);
$style = "width:".$matches[1]."px; height:".$matches[2]."px;";
echo $style;
?>
You can use str_replace
or a regular expression.
As concrete example:
$string = 'width="200" height="300"'
$string = str_replace('="', ':', $string);
$string = str_replace('"', 'px;', $string);
But beware, if there are also other attributes or s.th. else - regular expressions could be the better way.
Just don't use that output format of getimagesize()
if you're not going to include it directly.
Use first two values:
list($width, $height) = getimagesize("img/flag.jpg");
echo 'width:'.$width.'px; height:'.$height.'px;';