0

I would like to know how can i use variable here instead of constant. for ex I have this statement

<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/abc.css')?>"/>

Now Instead of abc.css , I want tomake it variable instead of hardcode value like $A = "abc.css" ; So statement should look like ==>

$A = "abc.css" ;
<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/$A')?>"/>

Please guide me, I'm not able to do it.

2
  • 6
    Learn to accept correct answers, then learn the very basics of PHP, take the baby steps, then come back on a programming forum. Commented Jul 3, 2011 at 10:21
  • @mario: all right. noted for further comments Commented Jul 3, 2011 at 13:10

3 Answers 3

4
<?php $A = "abc.css" ; ?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl("css/$A")?>"/>

Variables within double quoted strings are replaced.

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

Comments

1

Only code between <?php and ?> marks is considered and processed as PHP code. And you placed $A = "abc.css" ; outside these marks. So the code in <link> tag is trying to work with undeclared variable.

Also, only variables in double quoted strings are replaced.

Comments

1

Another way:

<?php $A = "abc.css" ; ?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/'.$A)?>"/>

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.