Kelvin Kelvin - 4 months ago 9
PHP Question

how to change some string based on database php

guys i have problem in change some part of string in

$menu_image
with this following code :

string(62) "/asset/images/menu/Singapore/365/225/509/509_RhWu2f4G_s130.jpg"


i want trying to change the
225
with a new string of number which i save it in
$category_id


example if i have
226
in
$category_id
than,
$menu_image
should be like this :

string(62) "/asset/images/menu/Singapore/365/226/509/509_RhWu2f4G_s130.jpg"


guys is that possible to change that
225
?

thank you (:

Answer

if your data always in same position. than its simple

just explode your code first

$split=array_map('trim', explode("/",$menu_image));
$split[6] = $category_id;
$menu_image_link = implode("/",$split);

than your $menu_image_linkwill return :

string(62) "/asset/images/menu/Singapore/365/".$category_id."/509/509_RhWu2f4G_s130.jpg"
Comments