2017-09-13 2 views
0

"font"디렉토리에 TTF 글꼴 파일이 더 있으면 섹션에 자동으로 추가하는 방법이 있습니까? PHP 파일을 사용하여 dir을 읽고 목록을 생성한다고 가정합니다 - 예? 이 같은스타일 시트에 자동으로 글꼴을 추가하는 방법은 무엇입니까?

(난이 스타일을 포함,하지만 난 폴더가 더 글꼴이 자동으로 경우이 같은 추가하려는 경우) :

<style type="text/css"> 

    @font-face 
    { 
    font-family: Baksoda; 
    src: url('fonts/Baksoda.ttf'); 
    } 

    @font-face 
    { 
    font-family: CherrySwash-Regular; 
    src: url('fonts/CherrySwash-Regular.ttf'); 
    } 

    @font-face 
    { 
    font-family: Riya-Black; 
    src: url('fonts/Riya-Black.ttf'); 
    } 
</style> 
+1

'I suppo PHP 파일을 열어서 목록을 생성 할 수 있습니다 - 예?'-이 방법은 그렇게 할 것 같습니다 –

답변

0

안녕 당신은 scandir()를 사용하여 시도 할 수 있습니다. 나는 에밀 Vikström에서이 대답을 찾고있다 :

Loop code for each file in a directory

이 어쩌면 이것은 당신에게 아이디어를 제공 할 수 있습니다 일단 :

<style> 
<?php 
$files = scandir('fonts/'); 
foreach($files as $file){ 
if(strpos($file,'.ttf') !== false){ 
echo "@font-face{font-family:".str_replace('.ttf','',$file).";src:url('fonts/".$file."')}"; 
} 
} 
?> 
</style> 
+0

감사합니다 mhhhan ..... 작동합니다 ............. ... :) –

0

이 코드는

<?php 
 

 
\t function getResultStyleString($directoryName) 
 
\t { 
 
\t \t $styleText = '<style type="text/css">'; 
 
\t \t 
 
\t \t $filesList = scandir($directoryName); 
 
\t \t 
 
\t \t foreach($filesList as $file) 
 
\t \t { 
 
\t \t \t if(strpos($file,'.ttf') !== false) 
 
\t \t \t { 
 
\t \t \t \t $styleText .= "@font-face{font-family:" . str_replace('.ttf', '', $file).";src:url('fonts/" . $file . "')}"; 
 
\t \t \t } 
 
\t \t } 
 
\t \t 
 
\t \t $styleText .= '</style>'; 
 
\t \t 
 
\t \t return $styleText; 
 
\t } 
 
\t 
 
\t $directoryName = "fonts/"; 
 
\t $resultStyleString = getResultStyleString($directoryName); 
 
\t 
 
\t var_dump($resultStyleString); 
 
?>
작동됩니다

관련 문제