将带有php代码的字符串显示为仅文本而不进行php解析

时间:2018-09-06 19:09:01

标签: php string parsing text

如何正确地将php代码仅作为文本(不解析)放入php字符串中?在它下面的部分工作,但输出中缺少很多字符串,我不知道为什么。编辑:使用htmlentities(),它可以工作,但是然后解析一些我不需要的东西。

此外,如果我在第一行中将”更改为“”,也​​会收到错误消息 可捕获的致命错误:在第75行的/home4/mjbourquin/public_html/auto_post_media.php中,无法将类IMDbapi的对象转换为字符串

编辑:htmlentities()也不起作用

我的代码:

$php_code = '<?php$imdb = new IMDbapi(';
$php_code = $php_code .  "'dqEaOSorwYCwxDDe0OcSAWzgtf9e7P'";

$php_code = $php_code . ")";
$php_code = $php_code . "$json = $imdb->get($imdbid,'json');";
$php_code = $php_code . '$data = json_decode($json)';

$php_code = $php_code . '$title = $data->title;$type = $data->type;$year = 
$data->year;$rated = $data->rated;$released = $data->released;$genres = 
$data->genre;$actors = $data->actors;$directors = $data->director;$plot = 
$data->plot;$countries = $data->country;$language = $data- 
>language;$metascore = $data->metascore;?>';

echo '<pre>' . htmlentities($php_code) . '</pre>';

输出:

<?php$imdb = new IMDbapi('dqEaOSorwYCwxDDe0OcSAWzgtf9e7P') 
{"imdb_id":"tt0055254","title":"One Hundred and One 
Dalmatians","year":"1961","rated":"","released":"25 January 1961 
(USA)","runtime":"79 min","genre":"Animation, Adventure, 
Comedy","director":"Clyde Geronimi ,","writers":"Bill Peet  (story), Dodie 
Smith  (novel)","actors":"Rod Taylor , Betty Lou Gerson , J. Pat 
O'Malley","plot":"Pongo and Perdita have a litter of 15 puppies. Cruella De 
Vil takes a fancy to the pups, and wants to get hold of them, as well as 
more pups, to make herself a lovely dalmatian skin coat... Cruella hires 
some thugs to kidnap the pups and hold them at her mansion. Will Pongo and 
Perdita find them in time...

可以看出html / php仍在解析一些我不需要的变量。

0 个答案:

没有答案