Jump to content

How to display/manipulate arrays in Php from preg_split?


hakhaimo

Recommended Posts

Hi! I am new here and I am also new to php since I am used to java(JSP)

 

below is my problem

 

This is my code:

<?php
$s = '<p>bleh blah</p><p style="one">one two three</p>';

$htmlbits = preg_split('/(<p( style="[-:a-z0-9 ]+")?>|<\/p>)/i', $s, -1, PREG_SPLIT_DELIM_CAPTURE);

//print_r($htmlbits);

$nElements = count($htmlbits);
$htmlArrays = array();

for($x=0; $x<$nElements; $x++)
{
echo "Number: ".$x." - ".$htmlbits[$x]."<br>";
}

?>

 

My expected output should be:

Number: 0 -

Number: 1 - <p>

Number: 2 - bleh blah

Number: 3 - </p>

Number: 4 -

Number: 5 - <p style="one">

Number: 6 - style="one"

Number: 7 - one two three

Number: 8 - </p>

Number: 9 -

 

My actual output is:

Number: 0 -

 

bleh blah

Number: 1 -

 

Number: 2 -

Number: 3 -

 

 

Number: 4 - style="one"

Number: 5 - one two three

Number: 6 -

 

Number: 7 -

 

THANK YOU VERY MUCH!!!!!!!!

I really need this badly!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.