NameSilo

I need help with string replace

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Thanks i will try that :)
 
0
Close
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back