格式化您的評論你上面有下面的代碼:
$userdatei = fopen("selltemplate/template.txt","r");
while(!feof($userdatei)) {
$zeile = fgets($userdatei);
echo $zeile;
}
fclose($userdatei);
// so i read in the csv file and the content of csv file one line:
// src="<?php echo $bild1; ?>" ></a>
這是假設$bild1
定義別的地方,但嘗試在您的while
循環中使用這些函數來解析並輸出您的html/php:
$userdatei = fopen("selltemplate/template.txt","r");
while(!feof($userdatei)) {
$zeile = fgets($userdatei);
outputResults($zeile);
}
fclose($userdatei);
//-- $delims contains the delimiters for your $string. For example, you could use <?php and ?> instead of <?php and ?>
function parseString($string, $delims) {
$result = array();
//-- init delimiter vars
if (empty($delims)) {
$delims = array('<?php', '?>');
}
$start = $delims[0];
$end = $delims[1];
//-- where our delimiters start/end
$php_start = strpos($string, $start);
$php_end = strpos($string, $end) + strlen($end);
//-- where our php CODE starts/ends
$php_code_start = $php_start + strlen($start);
$php_code_end = strpos($string, $end);
//-- the non-php content before/after the php delimiters
$pre = substr($string, 0, $php_start);
$post = substr($string, $php_end);
$code_end = $php_code_end - $php_code_start;
$code = substr($string, $php_code_start, $code_end);
$result['pre'] = $pre;
$result['post'] = $post;
$result['code'] = $code;
return $result;
}
function outputResults($string) {
$result = parseString($string);
print $result['pre'];
eval($result['code']);
print $result['post'];
}
歡迎來到Stack Overflow!這個問題在信息上有點短暫。你可以分享你的嘗試,並且遇到了什麼問題? – 2015-02-24 18:59:24
您是否嘗試將CSV行解析爲字符串,然後替換<?php php_code(); ?>用eval($ phpCode)? – 2015-02-24 18:59:49
*「因爲phpcode顯示爲」。*「 - 您的文件是否爲'.php'擴展名,並且PHP正在您所在的服務器上運行? @JayBlanchard * Gidday山姆* – 2015-02-24 19:06:26