01. februar 2007 - 17:45
Der er
5 kommentarer og 2 løsninger
Manipulering af streng i PHP
Jeg har brug for at få variablen $picture splittet op i mindre enheder. $picture = "<img src="uploads/thumb_22.jpg" width="276" height="246" border="0" alt="" title="" />" Jeg vil gerne ende op med følgende variable: $picture_path = "uploads/thumb_22.jpg" $picture_width = "276" $picture_width = "246" Disse værdier er selvfølgelig dynamiske.. Er der nogen som kan hjælpe mig? På forhånd tak!! =)
Annonceindlæg fra DE-CIX
01. februar 2007 - 18:06
#3
Strengen er et resultat af en funktion i TYPO3 CMS. Det er noget speciel kode som hedder TypoScript, som jeg ikke forstår mig meget på.. :o) $picturefile = $this->cObj->IMAGE($imgTSConfig);
01. februar 2007 - 18:20
#4
Første udkast: $streng = "<img src=\"uploads/thumb_22.jpg\" width=\"276\" height=\"246\" border=\"0\" alt=\"ALT\" title=\"TIT\" />"; $ny_streng = explode(" ", $streng); $src = $ny_streng[1]; $ny_src = explode("\"", $src); $src = $ny_src[1]; echo $src;
01. februar 2007 - 18:28
#5
Så skulle den være der: <?php $streng = "<img src=\"uploads/thumb_22.jpg\" width=\"276\" height=\"246\" border=\"0\" alt=\"ALT\" title=\"TIT\" />"; $ny_streng = explode(" ", $streng); // print_r($ny_streng); $src = $ny_streng[1]; $ny_src = explode("\"", $src); $picture_path = $ny_src[1]; $width = $ny_streng[2]; $ny_width = explode("\"", $width); $picture_width = $ny_width[1]; $height = $ny_streng[3]; $ny_height = explode("\"", $height); $picture_height = $ny_height[1]; // print_r($ny_streng); echo "\$picture_path = \"" . $picture_path . "\"<br />"; echo "\$picture_width = \"" . $picture_width . "\"<br />"; echo "\$picture_height = \"" . $picture_height . "\"<br />"; ?>
01. februar 2007 - 19:10
#7
Imponerende, hurtigt og meget brugbart svar! Tusind tak mccookie, jeg er utrolig glad for din hjælp!! :D