douweng7233 2013-06-19 11:22
浏览 6

在一定数量的字符后插入断点

How do I insert break point after certain number of break points

Like my string is ' Celebrating Founder’s Day ' and I call function to insert break point after 6 characters means it should return me ' Celebrating
Founder’s Day ' it should take the nearest space to insert the break point not at the character length given.

    if ( mb_strlen( $str) > $charlength ) {
        $subex = mb_substr( $str, 0, $charlength - 5 );
        $exwords = explode( ' ', $subex );
        $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
        if ( $excut < 0 ) {
            echo mb_substr( $subex, 0, $excut );
        } else {
            echo $subex;
        }
    } else {
        echo $str;
    }

I did not understand how to change this to insert the break point after certain characters

This code extracts the string of given character length

I did not understand this code to modify to insert break point after certain number of character length..

  • 写回答

1条回答 默认 最新

  • douqiju2520 2013-06-19 11:36
    关注

    Have not tried but basic logic:

    function breakPoint($string, $offset) {
        $place  = strpos($string, ' ', $offset);
        if($place !== false) {
            return substr($string, 0, $place)."
    ".substr($string, $place+1);
        }
    
        return $string;
    }
    

    You should look for strpos function.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?