0

What is the easiest way to modify something with PHP. suppose $link = http://www.example.com so what to do to modify this link and announce it in a new variable like this> $link_modified = http://my_example.com/go.html?http://www.example.com , can I use str_replace in this case or any other idea?

12
  • 1
    Why do you think you cannot modify it - this does not seem to be your real question Commented Sep 6, 2012 at 4:48
  • Why would you use medium-grade artillery like str_replace, when all you're doing is a simple string concatenation? Commented Sep 6, 2012 at 4:59
  • this is why, while fetching content i wanna modify all those links URL address automatically, but can not understand how to do it.. any idea? Commented Sep 6, 2012 at 5:03
  • regex will be your best friend Commented Sep 6, 2012 at 5:26
  • @StrikeForceZero any example? Commented Sep 6, 2012 at 6:16

3 Answers 3

1
$link_modified = "http://site.com/go.html?" . $link;

or if you meant in the same var

$link = "http://site.com/go.html?" . $link;
Sign up to request clarification or add additional context in comments.

Comments

1

I think you can do something like that:

$link = "http://www.example.com";
$link_modified = "http://site.com/go.html." . $link;

Comments

1

You can also use sprintf to return a formatted string.

$link = 'http://www.example.com';
$link_modified = sprintf('http://site.com/go.html?%s', $link);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.