2016-02-05 20 views
0

的問題是,我有串:如何Concat的在PHP中兩個字符串這是在波斯

$content=$rows["content"]; 

這是我從數據基地。刺痛檢索到的是波斯語。
我想說明的只有150 character.so我用:

$content=substr($content,0,150); 

,並表明這仍然繼續我需要證明3點:「......」 ,所以我所做的:

$content.='...'; 

當我通過回顯顯示此字符串時,我添加的3個點將出現在最後一行的右側。 但波斯語從右到左,因此3個點需要出現在最後一行的左側。

我厭倦了這樣的一個兩個,而是這一個沒有工作太

$content =iconv(mb_detect_encoding($content, mb_detect_order(), true), "UTF-8", $content); 
    $content=substr($content,0,150); 
    $dot='...'; 
    $dot =iconv(mb_detect_encoding($dot, mb_detect_order(), true), "UTF-8", $dot); 
    $content.=$dot; 
+3

substr()不能識別unicode,並將字符串視爲簡單的字節序列。您不能在unicode字符串上使用它,而不會損壞文本。這就是爲什麼有整個'mb _ *()'函數集,包括'mb_substr()' –

+1

嘗試$ content = mb_substr($ content,0,150,'utf-8') – Pooya

+0

@MarcB感謝您的answer.but它不起作用然而! – maktaf

回答

0

我只是增加了一個p標記與RTL各地要顯示我想要的文字這樣。像這樣:

  <p dir="rtl">'; 
      echo $content; 
      echo "..."; 
      echo '</p>';