我是很新的PHP所以我試圖尋找之前,我問這個問題,但我不能找到正確的答案。可能是因爲我不知道正確的詞彙。PHP的字替換
無論如何,這裏是我的問題:
我想從句子中刪除一個單詞。該句子是可以在網站上填寫的字段。
這句話在PHP是:
<?php the_field('years'); ?>
這工作,我得到正確的句子。所以,我想更換或隱藏字用:
<?php
$sentence = the_field('years');
$test = str_replace('the', ' ', $sentence);
echo "$test";
?>
但這只是呼應了$sentence
,別無其他。
如何做到這一點?什麼是像"the_field('years')
這樣的「對象」的正確詞彙?
謝謝!
編輯:
場實際上是一個Advanced Custom Field是爲WordPress。 要獲得Variable:
<?php
$variable = get_field('field_name');
?>
所以,我想:
<?php
$sentence = get_field('years');
$test = str_replace('the', ' ', $sentence);
echo "$test";
?>
但是,這將ECHOE: 「陣列」
'the_field( '年');'是呼叫被叫the_field與參數年功能。這是你想要的嗎?也許你想得到一個數組中元素的值,你可以用$ the_field ['years']得到它的值。 – quidage
請顯示「the_field」功能的來源。 – bbldzr
實際上「the_field」迴響了一系列名爲「年」的字段。 – Trekdrop