0

Ok so in Python, I could have a URL like

"(www.google.com/%s)" % cat

and the output would be

"(www.google.com/cat)"

How do I do this in PHP? I don't want to echo the output out, I want to scrape a given URL based on user input (i.e., they put in a stock ticker and it will go to the page of that stock ticker)

1 Answer 1

1

You are looking for sprintf (or possibly vsprintf, if that would be more convenient).

$url = sprintf("(www.google.com/%s)", "cat");
echo $url;                                    // result: (www.google.com/cat)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I didn't actually have to do that, I just split the URL in two and concatenated it back with the ticker inside. Though I may try this method too! I don't know which is more efficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.