Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

[Resolved] PHP Question

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Archangel

randypendleton.comTop Member
Impact
1,775
PHP Question

Simple question: Can I use replace() in PHP to change text in a document? If not, does anyone know how to go about this?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
1
Close
Eric said:
replace? No, but you can use www.php.net/str_replace


I'm not too good at PHP. Sadly, this kinda confuses me. Let's say I want to replace all instances of site1.com with site2.com. Exactly how would I write that out? This function seems to require 3 parameters...
 
0
Close
PHP:
$string = "I'm not too good at PHP. Sadly, this kinda confuses me. Let's say I want to replace all instances of site1.com with site2.com. Exactly how would I write that out? This function seems to require 3 parameters...";

$string = str_replace(array('site1.com', 'site2.com'), '', $string);

Archangel said:
I'm not too good at PHP. Sadly, this kinda confuses me. Let's say I want to replace all instances of site1.com with site2.com. Exactly how would I write that out? This function seems to require 3 parameters...
 
0
Close
Eric said:
PHP:
$string = "I'm not too good at PHP. Sadly, this kinda confuses me. Let's say I want to replace all instances of site1.com with site2.com. Exactly how would I write that out? This function seems to require 3 parameters...";

$string = str_replace(array('site1.com', 'site2.com'), '', $string);


Looks good but I need to ask: What is $string referring to the top text? Is that the text that I want the script to look through & make the necessary replaces to? lol I know a little PHP but this is something outta my league.
 
0
Close
Archangel said:
Looks good but I need to ask: What is $string referring to the top text? Is that the text that I want the script to look through & make the necessary replaces to? lol I know a little PHP but this is something outta my league.
Ah, yes - it refers to what text you're wanting PHP to perform the replacements on.
 
0
Close
Eric said:
Ah, yes - it refers to what text you're wanting PHP to perform the replacements on.

Thanks for your help on this :) Reps added
 
0
Close
No problem, and thanks. :tu:
 
0
Close
is it just me or does $string = str_replace(array('site1.com', 'site2.com'), '', $string); just remove all instances of site1.com AND site2.com... i thought he said he had wanted to convert site1.com into site2.com?

in which case you'd have to do: $string = str_replace('site1.com', 'site2.com', $string);
 
1
Close
nasaboy007 said:
is it just me or does $string = str_replace(array('site1.com', 'site2.com'), '', $string); just remove all instances of site1.com AND site2.com... i thought he said he had wanted to convert site1.com into site2.com?

in which case you'd have to do: $string = str_replace('site1.com', 'site2.com', $string);
Ah, good catch - I read it as he wanted to replace them both. :red:
 
0
Close
nasaboy007 said:
is it just me or does $string = str_replace(array('site1.com', 'site2.com'), '', $string); just remove all instances of site1.com AND site2.com... i thought he said he had wanted to convert site1.com into site2.com?

in which case you'd have to do: $string = str_replace('site1.com', 'site2.com', $string);

I just tested the code out and it ran albeit not the way I intended. But it's cool -- I think I could have done better had I typed my replies a bit clearer :)
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back