1

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?

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Great, #2 worked perfectly and I learnt something along the way. Thanks.
1

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

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

Comments

0

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

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

Comments

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.