Split() function is deprecated

Hello good sirs!

I truly know nothing about php, but know far more regarding computers and software than anyone else in the office here. I know exactly what needs to be changed, but have no idea to what I should be changing it to. I do know that the split function is being replaced in favor of the PCRE equivalent or so I’ve read. According to that website, preg_split() is the function I am looking for, but I have no idea what other things need to be changed since changing just that line won’t do much.

Here is the code for the function it’s referring to…

[php]function wordwrapnew( $string, $cols = 80, $prefix = “”, $splitwith = “\n” )
{
$t_lines = split( “\n”, $string);
$outlines = “”;

while(list(, $thisline) = each($t_lines))
{
  if(strlen($thisline) > $cols)
  {
    $newline = "";
    $t_l_lines = split(" ", $thisline);

    while(list(, $thisword) = each($t_l_lines))
    {
	  while((strlen($thisword) + strlen($prefix)) > $cols)
	  {
	    $cur_pos = 0;
	    $outlines .= $prefix;

	    for($num=0; $num < $cols-1; $num++)
	    {
		  $outlines .= $thisword[$num];
		  $cur_pos++;
	    }

	    $outlines .= $splitwith;
	    $thisword = substr($thisword, $cur_pos, (strlen($thisword)-$cur_pos));
	  }

	  if((strlen($newline) + strlen($thisword)) > $cols)
	  {
	    $outlines .= $prefix.$newline.$splitwith;
	    $newline = $thisword." ";
	  }
	  else
	  {
        $newline .= $thisword." ";
	  }
    }

    $outlines .= $prefix.$newline.$splitwith;
  }
  else
  {
    $outlines .= $prefix.$thisline.$splitwith;
  }
}

return trim( $outlines );

}[/php]

This is part of a web page that uploads files to us. We then access those files using an ftp program. I may have answers to questions, but I don’t know how much help I can be. As I said, I don’t know anything about php.

I think you need delimiters with preg_split()

[php]
preg_split( “/\n/”, $string);
[/php]

This does remove the errors that I had encountered before, but it still doesn’t upload any information. If I need to provide more of the code I can.

Regex is not really my thing maybe be better off asking in the regex forum.

But the backslash might need to doubled
[php]
preg_split( “/\n/”, $string);
[/php]

or maybe
[php]preg_split("/[\n]/", $string);[/php]

[php]
preg_split("/\n/", $string, PREG_SPLIT_NO_EMPTY);
[/php]

Sorry I did not see the second one

[php]
$t_l_lines = preg_split("/ /", $thisline);
[/php]

[php]
$t_lines = preg_split( “/\n/”, $string); $outlines = “”;
while(list(, $thisline) = each($t_lines)) {
if(strlen($thisline) > $cols) {
$newline = “”;
$t_l_lines = preg_split("/ /", $thisline);
[/php]

[php]
$t_lines = preg_split( “/\n/”, $string);
$outlines = “”;
while(list(, $thisline) = each($t_lines)) {
if(strlen($thisline) > $cols) {
$newline = “”;
$t_l_lines = preg_split("/ /", $thisline);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service