jnrcoder
jnrcoder

Reputation: 23

passing php variable into html

I'm new to php so pardon the ignorance
I'm trying to include a php variable, it is and is not working.

$currentdata = file_get_contents("http://www.abr.business.gov.au/abnDetails.aspx?abn=$abn");

This works with $abn being the variable being passed from earlier being set.

$abntypedata = '/d$abn&amp;ResultListURL=">(.+?)</'; This does not work.
$abntypedata = '/d33051775556&amp;ResultListURL=">(.+?)</'; This does.

I need to be able to use the variable $abn to insert that number as it will be user defined. Why is this not working?

Upvotes: 1

Views: 185

Answers (4)

brenjt
brenjt

Reputation: 16297

Try adding Double Quotes around the string " not ' that should render the variables other wise do this:

$abntypedata = '/d'.$abn.'&amp;ResultListURL=">(.+?)</';

Upvotes: 0

Mohamed Nuur
Mohamed Nuur

Reputation: 5645

Php is perticular about the quotations. You have to use double quotes to include variables:

$abntypedata = "/d$abn&amp;ResultListURL=\">(.+?)</"; This works

or

$abntypedata = '/d'.$abn.'&amp;ResultListURL=">(.+?)</'; This works

Upvotes: 1

John Flatness
John Flatness

Reputation: 33749

You can't use inline variables like that in single-quoted strings.

$abntypedata = "/d$abn&amp;ResultListURL=\">(.+?)</";

Upvotes: 1

Tieson T.
Tieson T.

Reputation: 21191

Variable substitution does not occur with single quotes. Change those to double quotes and should work.

EDIT: FYI, here's the PHP manual for strings in PHP. It's useful to know what the various types of strings are: http://www.php.net/manual/en/language.types.string.php

Upvotes: 4

Related Questions