douchuang8359 2014-05-25 06:48
浏览 99
已采纳

将范围或某些标记添加到短语中的其他语言文本

In a PHP variable a mixed language context is present. An example is below:

$variable="This is sample text I am storing in the variable. இதன் கூடவே மற்ற மொழி எழுத்துக்களும் உள்ளன"

So the variable $variable contains both English and other language (Tamil in the above example).

Now I need to add a tag with class something enclosing the Tamil text such as:

$variable="This is sample text I am storing in the variable. <span class='tamil'>இதன் கூடவே மற்ற மொழி எழுத்துக்களும் உள்ளன</span>"

How to omit the English letters and punctuation symbols and add <span> to other language sentence completely or paragraph?

  • 写回答

2条回答 默认 最新

  • douzhao2047 2014-05-25 07:45
    关注

    As Filype mentioned, we can use the unicode ranges for this.

    This should match even in cases like 'English' -> 'Tamil' -> 'English' -> 'Tamil'. Though it'll wrap extra spaces into the span.

    /**
     * @param String $str Input UTF-8 encoded string.
     */
    function encapsulate_tamil($str)
    {
       return preg_replace('/[\x{0B80}-\x{0BFF}][\x{0B80}-\x{0BFF}\s]*/u',
          '<span class=\'tamil\'>$0</span>', $str);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错