0

I would like to assign a variable into the PHP code, which will change my URL. For example

$page = 'http://www.example.com/search-products?type=buildings&q=small&go=Go';

Where q=small i would like to change to say q=big (using a variable)

I have assigned a variable within PHP but i am unable to get it to work?

for example $q= 'big';

$page = 'http://www.example.com/search-products?type=buildings&q=$q&go=Go';

The url does not however update - Any help would be appreciated

Rotimi
  • 4,783
  • 4
  • 18
  • 27
John
  • 321
  • 5
  • 16

2 Answers2

1

Use strings with " and not with ' if you're using variables in it.

$page = "http://www.example.com/search-products?type=buildings&q={$parameter}&go=Go";

1

Check this :

$page = "http://www.example.com/search-products?type=buildings&q={$q}&go=Go";

Note: Single quotes don't work in this case. If you use Single quotes, you see something like this :

echo 'q={$q}';
//Output => q={$q}