Dynadot โ€” .com Registration $8.99

I need help with string replace

Spaceship Spaceship
Watch

oberheimer

Established Member
Impact
51
Here is the code that i use


$rs_products_image_large=str_replace('images/','images/1_',$products_image_large);
$rs_products_image_large_1=str_replace('images/','images/1_',$products_image_large);

I want to change so the replaced image is products_image_large_1
instead of 1_products_image_large

But im not good at coding :p
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
<?php
function my_custom_replace($s, $format) {
	$base = basename($s);
	$dir = dirname($s).'/';
	$a = explode('.', $base);
	$ext = array_pop($a);
	$clean_file = implode('.', $a);
	$new_file = sprintf($format, $clean_file).'.'.$ext;
	return $dir.$new_file;
}

$products_image_large = 'images/example/blue_shoes.jpg';
$rs_products_image_large = my_custom_replace($products_image_large, '%s_1');

echo $rs_products_image_large;
?>

Output :
Code:
images/example/blue_shoes_1.jpg

I hope it helps.
 
0
•••
Thanks i will try that :)
 
0
•••
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back