Php 正在字符串中处理的html_替换为变量
我有一个htmlPhp 正在字符串中处理的html_替换为变量,php,variables,replace,Php,Variables,Replace,我有一个html[VALUE],其中[VALUE]在处理模板时被替换为一些数据 我想在php变量中使用替换[VALUE]的数据 像这样的,, $my_var='[VALUE]' 但上述方法不起作用 function getHTML($articleid, $fieldid, $category = false, $write=false) { global $globalreturn; //$str = fieldattach::getInput($art
[VALUE]
,其中[VALUE]
在处理模板时被替换为一些数据
我想在php变量中使用替换[VALUE]
的数据
像这样的,,
$my_var='[VALUE]'代码>
但上述方法不起作用
function getHTML($articleid, $fieldid, $category = false, $write=false)
{
global $globalreturn;
//$str = fieldattach::getInput($articleid, $fieldid, $category);
$html ='';
$valor = fieldattach::getValue( $articleid, $fieldid , $category );
$title = fieldattach::getName( $articleid, $fieldid , $category );
$published = plgfieldsattachment_input::getPublished( $fieldid );
if(!empty($valor) && $published)
{
$html = plgfieldsattachment_input::getTemplate($fieldid);
if(fieldattach::getShowTitle( $fieldid )) $html = str_replace("[TITLE]", $title, $html);
else
$html = str_replace("[TITLE]", "", $html);
$html = str_replace("[VALUE]", $valor, $html);
$html = str_replace("[FIELD_ID]", $fieldid, $html);
}
//WRITE THE RESULT
if($write)
{
echo $html;
}else{
$globalreturn = $html;
return $html;
}
}
function getTemplate($fieldsids, $file="input", $valor)
{
global $globalreturn;
echo $valor;
$templateDir = dirname(__FILE__).'/tmpl/'.$file.'.tpl.php';
$html = file_get_contents ($templateDir);
$app = JFactory::getApplication();
$templateDir = JPATH_BASE . '/templates/' . $app->getTemplate().'/html/com_fieldsattach/fields/'.$file.'.tpl.php';
if(file_exists($templateDir))
{
$html = file_get_contents ($templateDir);
}
$app = JFactory::getApplication();
$templateDir = JPATH_BASE . '/templates/' . $app->getTemplate().'/html/com_fieldsattach/fields/'.$fieldsids.'_'.$file.'.tpl.php';
if(file_exists($templateDir))
{
include ($templateDir);
}
//return $html;
}
我正在尝试使用$valor表单函数getHTML();在getTemplate()中;
正如您将在上面的代码中看到的,我已经尝试调用global$globalreturn,然后调用echo$valor;但它不起作用。您可以尝试以下方法
我想您需要将变量传递到另一个页面。因此,在myfile.php中添加以下代码
<h1 class="title"><?php define ( 'myVariable', '[VALUE]' ); ?></h1>
并在下一页中使用require函数调用
<?php
require("myfile.php");
?>
请发布一些代码嗨,它不起作用。让我试着重新表述我的问题。如何在名为unsing file_get_content('myfile.php')的php文件中使用php标记;使用require(“myfile.php”)添加和调用;谢谢,没用。我决定只创建类变量并在我的文件中调用它们。最初我的目标是不更改此扩展核心文件,但我已经在上面花费了太多时间。:)如果我使用require调用该文件,它将显示数字1,而不是值。请不要使用$sign-in define函数。只需使用myVariable。像echo myVariable;嗨,阿什德,我又试了一次。还是不走运。我照你的建议做了。我使用“require”和