The width example uses string length instead since I know it will always be at the end of the string. This is why there is subtraction done when calculating the height. Substr requires the string it will be processing, the starting point, and the LENGTH of the string to capture. It then figures out the starting and ending position of where the delimiter is found. You don't need to use multiple characters like I did, but make sure you have enough characters so it doesn't capture something else in the string. Then figure out where each delimiter starts and ends. You can also set them programmatically if you wish. $width = substr($imageURL, $strPosStart, $strPosEnd) īasically, define your string delimiters. $height = substr($imageURL, $strPosStart, $strPosEnd) ![]() $strPosEnd = strpos($imageURL, $secondDelimiter)-$strPosStart $strPosStart = strpos($imageURL, $firstDelimiter)+3 Here is working code that I used to find the height and width of an image using delimiters, strpos, strlen, and substr. Some of the answers related to strpos, strlen, and using delimiters are wrong. ![]() Use the stripos() function to search for the substring case-insensitively.There's a lot of good answers here.Use the strpos() function to return the index of the first occurrence of a substring in a string.Var_dump($position) // 0 Code language: PHP ( php ) Summary To search for a substring case-insensitively, you use the stripos() function:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |