CSS ファイルを読み取ってプロパティの値を返すために作成した短い関数があります。問題は、必要な値を超えて読み取り、間違ったファイルにさらに値を返すことです。
関数は次のとおりです。
function get_css($f, $tag, $el) {
$css = fopen($f, "r");
$line = fgets($css);
while ( !feof($css) ) {
if(strpos($line, $tag) > 0) {
while ( !feof($css) ) {
$line = fgets($css);
if (strpos($line, $el) > 0) {
return substr(substr($line, strpos($line, ":")+1), 0, -1);
}
}
}
$line = fgets($css);
}
}
これが私の呼び方です。
$ew = get_css("1688_style.css", "elevations", "width");
そして、これが読み取っている CSS ファイルのサンプルです。
Body {
margin:0;
color:black;
width:100%;
height:100%;
margin-left:auto;
margin-right:auto;
padding:0px;
font-family:arial,sans-serif;
background-color:#FFFFFF;
}
#Content {
position:relative;
display:inline-block;
background-color:#FFFFFF;
margin-top:30px;
margin-left:80px;
width:1520px;
}
#elevations {
position:relative;
display:inline-block;
width:250px;
text-align:center;
}
#views {
display:inline-block;
cursor:pointer;
margin-top:20px;
margin-left:15px;
}
#help {
position:absolute;
width:50px;
text-align:center;
font-size:12px;
top:18px;
right:20px;
}
私が期待しているのは 250px ですが、#help タグから得られるのは 50px です。ここで何を試すかについてのアイデアが不足しています。