2012-05-18 99 views
0

在這個關聯數組中,我只有包含空格的文本字符串。當我訪問數組的一個元素來打印文本時,我只能得到第一個單詞。如何用空格檢索所有文本?PHP關聯數組的字符串只返回第一個字

$feast_description = array('Mother_of_God' => 'Recognition of the Blessed Virgin Mary as the Mother of Jesus who is the Son of God and is God Himself.', 
    'Epiphany' => 'Recognition of Jesus by the Magi as one sent by God.', 
    'Baptism_of the Lord' => 'Jesus asks of John the Baptist that he baptize Him in the Jordan river. This act was to teach us of the necessity of baptism to be washed clean of our corruption for admittance among God\'s children and for salvation. This day God also revealed Jesus to be His Son.', 
    'Presentation_of_the_Lord' => 'Jesus as first born of the Holy Family is presented at temple and consecrated to God.', 
    'Ash_Wednesday' => 'Beginning of Lent the season of penance to make up for our sins and draw nearer to God in preparation for Easter.', 
    'Holy_Thursday' => 'First feast of the Easter Triduum. We commemorate the Last Supper when Jesus began the Sacrament of the Eucharist. On that day He also gave an example of service and of humility by washing the feet of His disciples.','Good_Friday' => 'Day of the Passion of Jesus when He was crucified and died to offer His life in reparation for our sins. By giving up His earthly life as a sacrifice to God the Father, He earned for us divine life, eternal life with the Father in Heaven.', 
    'Holy_Saturday' => 'A day of waiting between Good Friday and the Resurrection of the Lord on Easter Sunday morning. On the vigil of Easter the Church celebrates a special liturgy which traces the history of salvation.', 
    'Easter' => 'Jesus who was crucified three days earlier, went among the dead, descended into hell and returned to life victorious over death. He won that victory for all mankind. Upon the Resurrection of Jesus is founded the hope of every Christian that we too will conquer death.', 
    'Ascension' => 'Jesus returns to the Father, having fulfilled His mission on earth, to teach us of the Father\'s love, show us His commands, and teach us the way back to Him. He did not linger in His earthly life to be our intercessor and our advocate at the right hand of the Father. By ascending to the Father Jesus secures our place with Him. He returns to the Father, taking up with Him all of humanity and forever defeats the one who constantly seeks to separate us from our God.', 
    'Pentecost' => 'Jesus promised that He would not leave us by ourselves as He returns to the Father. He promised to send a paraclete, a helper, an advocate. He does on Pentecost, He sends the Holy Spirit, to be with us in this new manner and to remain with us until the end of time.', 
); 

此數組元素

$feast_description['Mother_of_God'] 

只返回字Recognition,該串中的第一個字。

我輸出標記的title中的字符串,並用這樣的echo語句。

echo ' '.$litweek.' week <a title='.$feast_description['Mother_of_God'].'>'.$litsea.'</a>&nbsp;&#8226;'; 

什麼是獲得所有文本的正確方法?

+0

如果將值放在雙引號中,您會得到不同的結果嗎? ''Mother_of_God'=>「認識聖母......」? – Ryan

+3

你的數組定義是正確的。你究竟是從陣列「返回」的? –

+1

你可以顯示你用來輸出這個數組值的代碼嗎? –

回答

0

超出了數組元素周圍缺少引號。 HTML必須指定爲

echo ' '.$litweek.' week <a title="'.$feast_description['Mother_of_God'].'">'.$litsea.'</a>&nbsp;&#8226;'; 

用雙引號$ feast_description。

0

試試這個:

foreach ($feast_description as $name => $text) { 
    echo $name . " : " . $text . "<br/>"; 
} 
1

我認爲你需要減肥括號之前的點,應該是這樣的:

$feast_description['Mother_of_God'] 
0

而不是回聲你可能想嘗試使用打印格式並傳入值。它使編寫html更容易,並保持值的整潔。

printf(' %s week <a title="%s">%s</a>&nbsp;&#8226;', 
    $litweek, $feast_description['Mother_of_God'], $litsea); 
相關問題