2011-08-31 66 views
0

尋找我的問題的解決方案。 搜索這個地方和谷歌的答案,但不能獲得太多的理由。php ltrim不抓取開始破折號

基本上我想從標題中刪除「Issue 119 - 」。

到目前爲止,我得到了「問題119」被刪除,但「 - 」是可悲的 任何人都可以幫助我。會喜歡它,如果我可以修改$ cut變量線

$ grissueno來自我的wordpress post = 119字符串中的自定義字段。

the_title呈現字符串 「問題119 - 編輯:四面」(如題)

<?php 
$cut = "Issue " . $grissueno; //joining the word issue and dynamic number together 
$title = the_title('','',false); //telling wordpress to let php use the title string 
$trim = str_replace($cut, "", $title); //cutting out the Issue 119 
echo ltrim($trim, " - "); //trying to remove the dash but failing 
?> 

感謝您的幫助

+0

http://php.net/manual/en/function也許審查。 ltrim.php會幫助 –

+0

對不起,我注意到我發佈了一個編輯代碼試圖加載不同的東西,我發佈之前認爲它是str_replace:/ echo ltrim($ trim,「 - 」); – Trevor

回答

0

變化$cut = "Issue " . $grissueno;$cut = "Issue " . $grissueno . " - ";,忘記ltrim()

+0

由於某些原因,因爲「 - 」它不會刪除$ cut字符串:/不知道發生了什麼 – Trevor

+0

哦謝謝修復傢伙> _ <所有巨型幫助發現它是一個–不是破折號 使用65Fbef05的答案,但像這樣修改它。 $ cut =「Issue」。 $ grissueno。 「–」; 感謝v多 – Trevor

3

ltrim只需要兩個參數。要修剪的字符串以及可修剪的字符列表:

$trim = ltrim($title, "- "); 

是您想要的。你正在修剪一個空字符串("")。

+0

是啊這是我想發佈最初對此感到抱歉......它沒有接縫工作......不知道爲什麼tho – Trevor

+1

你確定這是短短的文字?可能是–甚至是— –

0

試試這個:

$title = "Issue 119 - Editorial: Troubled on every side"; 
echo preg_replace('/Issue \d+ - (.*)/', '$1', $title); 
0

嘗試用替換一大堆:(EDITED

echo ltrim(str_replace("Issue $grissueno",'',the_title('','',FALSE)),"- \t\n\r\0\x0B");