PHP:在长度700和之后将字符串拆分为2。 (期)

问题描述:

I cant seem to figure the best approach to a PHP problem. I want to accomplish the following

  1. I get a string that is, ie. 1000 characters in lenght
  2. I want to split a string into 2.
  3. The first string need to be 600 characters based on the following condition: a) String should only be split if after a period
  4. The second section of the string can be the remainder.

I know how to check the length of a string strlen($string) and I know how to explode a string into substrings using ie. explode(). However, I am not sure how to bring everything together.

我似乎无法找到解决PHP问题的最佳方法。 我想完成以下内容 p>

  1. 我得到一个字符串,即。 长度为1000个字符 li>
  2. 我想将字符串拆分为2。 li>
  3. 根据以下条件,第一个字符串需要为600个字符: a)字符串应该 只有在一段时间后才被拆分 li>
  4. 字符串的第二部分可以是余数。 li> ol>

    我知道如何检查 字符串 strlen($ string) code>的长度,我知道如何使用ie将字符串分解为子字符串。 爆炸()代码>。 但是,我不确定如何把所有东西放在一起。 p> div>

I have used, its works.. you have try this...

<?php
        $app_title="HIOX INDIA.COM, a leading business web hosting company, is

   currently involved in web services, software/application development, web content 

   development, web hosting, domain registration, internet solutions and web design.";

        echo "<br>Before :".$app_title;
        $length=100; 
        if(strlen($app_title) > $length) { 
        $app_title1 = substr($app_title, 0,strpos($app_title, ' ', $length));}
        $app_title2=split ( $app_title1 , $app_title);
        echo "<br><br>After1 :".$app_title1;
        echo "<br><br>After2 :".$app_title2[1];

?>

  1. Use substr() to yank out everything after 600 chars from the original string.
  2. Do a strpos() on that resulting sub-string to find the first .
  3. Use the pos + 600 to do a substr on the original string and use that position as your split point.

Using substr() you can get part of a string defining a initial position and the lenght of the substring. For example:

Getting the first 600 characters:

$first = substr ( $input , 0 , 600 );

Getting the remaining:

$second = substr ( $input , 600 );