|
 |
|
สอบถามเรื่องการส่งตัวแปรจาก php ไปยัง css ครับ ช่วยหน่อยคับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
$bgcolor = "red";
?>
div.css
{
background-color:<?=$bgcolor;?>;
}
|
 |
 |
 |
 |
Date :
2012-08-22 23:04:28 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้คับ
|
 |
 |
 |
 |
Date :
2012-08-22 23:13:48 |
By :
กกกก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไปเขียนในไฟลื .css ใช่ไหมนั่น
|
 |
 |
 |
 |
Date :
2012-08-22 23:15:05 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมประกาศตัวแปรไว้ในไฟล์ php
ส่้วนอันนี้ไฟล์ css ที่ผมจะส่งตัวแปรเข้าไป
<link rel="STYLESHEET" type="text/css" href="codebase/testcss.css">
|
 |
 |
 |
 |
Date :
2012-08-22 23:18:56 |
By :
ัเด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<link rel="STYLESHEET" type="text/css" href="codebase/testcss.php">
จากนั้นในไฟล์ echo ออกมาในรูปแบบของ css แค่นั้นก็ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2012-08-22 23:24:16 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ แก้เป็น .php แล้ว แต่ยังเหมือนเดิมเลยครับ
|
 |
 |
 |
 |
Date :
2012-08-22 23:30:39 |
By :
กกก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณไปทำยังไงก็ไม่บอก บอกแค่ว่าไม่ได้ ต้องให้เดากันอยู่เรื่อย 
|
 |
 |
 |
 |
Date :
2012-08-22 23:54:22 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<link rel="stylesheet" type="text/css" href="codebase/testcss.php">
$bgcolor ="red";
***ภายในไฟล์ codebase/testcss.php
Code (PHP)
div.css
{
background-color:<?=$bgcolor;?>;
}
คือผมจะส่งตัวแฟรที่เป็น code สีเข้าไปใน css ครับ
|
 |
 |
 |
 |
Date :
2012-08-23 00:02:45 |
By :
กกก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยก $bgcolor ="red"; ไปไว้ข้างบน <link
|
 |
 |
 |
 |
Date :
2012-08-23 00:04:56 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
555+ ยกแล้วครับ ไม่ได้เหมือนกัน
|
 |
 |
 |
 |
Date :
2012-08-23 00:11:45 |
By :
กกก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่งแบบ get ละกัน
index.php
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS</title>
<?php
$color = 'green';
?>
<link rel="stylesheet" type="text/css" href="css.php?color=<?php echo $color; ?>"/>
</head>
<body>
</body>
</html>
css.php
Code (PHP)
<?php
header("Content-type: text/css");
echo 'body{background:' . $_GET['color'] . '}';
?>
|
 |
 |
 |
 |
Date :
2012-08-23 00:22:38 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ได้ละครับ
|
 |
 |
 |
 |
Date :
2012-08-23 01:43:39 |
By :
กกก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|