/    Sign up×
Community /Pin to ProfileBookmark

I’m new to PHP and so don’t know how to get around this problem.

I have 2 php scripts and i want to display a variable from one of the srcipts in the other script. To display a variable in HTML I use

[code=php]
<?php echo $somevariable; ?>
[/code]

If I put this variable in my HTML it displays correctly. But when I put it inside the other PHP code it doesn’t work. When I view source the above code is displayed instead of just the variable.

I should say that script 1 decides which stylesheet to print into the HTML. Script 2 generates a random number from an array, which then needs to be printed with script 1.

Does that make sense? Probably not. I’ve found it hard to explain. Another way to look at is: How can I have this:

[code=php]
<?php

script 1

<?php echo $variable_from_script2; ?>

script 1

?>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriJul 03.2004 — [code=php]<?php

script 1

<?php echo $variable_from_script2; ?>

script 1

?>[/code]


instead of that, use this

[code=php]<?php

script 1

echo $variable_from_script2;

script 1

?>[/code]
Copy linkTweet thisAlerts:
@richiebmanauthorJul 03.2004 — That was close 96, but didn't work. But gave me an idea.

I turned the result of script 2 into a variable and found out how to nest two variables:

[code=php]
<?php
$script_1_variable = 'HTML code etc' . $script_2_variable_result . 'HTML code etc';
?>
[/code]


So now the thread title should have been

Variable inside Variable

Cheers,

R
Copy linkTweet thisAlerts:
@96turnerriJul 03.2004 — o i c i just re read your original post, yes thats how i would do it too
×

Success!

Help @richiebman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...