How do I complete these strings
I am trying to create/complete URL paths. I am given a开发者_开发百科 bunch of sku numbers that need to be inserted into a url.
Example URL:
http ://www.website.com/image/1111-large.jpg
http ://www.website.com/image/1112-large.jpg
Im guessing it would look something like this?
print("http://www.website.com/image/$sku-large.jpg")
Example of given Sku numbers:
1111 1112 1113 1114 I need to echo these strings out.I am very very new to PHP. Thanks for the help!
Looks to me like you are 99% of the way there.
$skus = array(1111,1112,1114,1115,11116);
foreach ($skus as $sku)
{
echo "http://www.website.com/image/$sku-large.jpg\n";
}
What you wrote,
print("http://www.website.com/image/$sku-large.jpg");
should work. (Note the semicolon at the end of the line).
Did you try it?
I do not know where those "Sku numbers" are coming from, but this is how you add a variable to a string:
echo 'http://www.website.com/image/'.$sku.'-large.jpg';
I am using the concatenation operator (.
) to append the variable to the string.
精彩评论