Вопрос

$base64image = "data:image/png;base64,iVBOR(...)5CYII=";

I need to cut off the first part of the string and stop when the comma is cut off, so only "iVBOR(...)5CYII=" remains, since I'm using a function that doesn't support the current format using the "data:image/;base64," at the beginning, I need it to be always cut off the string.

PS: The length of the string before the commas can differ :/

How could I achieve this?

Это было полезно?

Решение

Try this

$result = substr(strstr($base64image, ','), 1);

Другие советы

A combination of strpos, and substr like so...

$comma_pos = strpos($base64image,',');
$base64image = substr($base64image,$comma_pos + 1);

Another one using explode:

echo explode(",", $base64image)[1];

outputs:

iVBOR(...)5CYII=
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top