<?
$text= "[align=center]
pictureit(2265:border:150::1:0:1) pictureit(2266:border:150::1:0:1) pictureit(2269:border:150::1:0:1)[/align]";
$text = explode(" ", $text);
	foreach ($text as $key){

$matched = preg_match('/.*pictureit\(.*\).*/', $key);
    if ($matched == 1){

$data = preg_replace("/.*pictureit\(/", "", $key);
$data = preg_replace("/\).*/", "", $data);
//$key = str_replace(")", "", $key);
list($id, $style, $width, $height, $comments, $float, $link) =
   split(":", $data, 7);
echo "<br><b>id:$id<br>style:$style<br>width:$width<br>height:$height<br>comments:$comments<br>float:$float<br>link:$link</b><br>";
}
}
?>

I have set $text as an example of the situation i came accross when trying to test my function. the $id should read an int, but rather it gives me the [align stuff because its on the top line and not considered a space that preg_replace could take out after $matched == 1.. Any ideas on how to remove the line break in the $data variable but not the $key.. Any help much appreciated, thanks alot

CHADian

    for some reason it counts the thing after align=center as a space, and it doesnt explode because its a line break, but in the array form it keeps joined by the space.. so i don tknow

      If you don't tack an s on the end of the regexp (after the final /), then . will not match newline characters.

      Also, unless it is immediately followed by ?, then * will attempt to match as many characters as it possibly can.

      Anyhoo, does this do better (I can't check right now; :

       $text= "[align=center] pictureit(2265:border:150::1:0:1) pictureit(2266:border:150::1:0:1) pictureit(2269:border:150::1:0:1)[/align]";
      preg_match_all('/pictureit\((.*?)\)/', $text, $pictureits);
      foreach($pictureits[1] as $pictureit)
      {
           list($id, $style, $width, $height, $comments, $float, $link)
          = explode($pictureit);
          echo "<br><b>id:$id<br>style:$style<br>width:$width<br>height:$height<br>comments:$comments<br>float:$float<br>link:$link</b><br>";
      } 

        Warning: Wrong parameter count for explode() in g:\apache\www\upcoming\includes\test.php on line 8

          change the explode($pictureit) to explode(":",$pictureit)

            Blasted rinky-dink http client I'm using here. You're lucky you got linebreaks in the code :glare:🙂 - but you couldn't work out what the problem with it was?

              I'm so so so ..sorry to say,i test you code and it runs OK!

              <?php
              $text= "[align=center] 
              pictureit(2265:border:150::1:0:1) pictureit(2266:border:150::1:0:1) pictureit(2269:border:150::1:0:1)[/align]"; 
              
              $reg = "/[(]([^)]*)[)]/";
              preg_match_all($reg ,$text, $matches, PREG_PATTERN_ORDER) or die('Found none!');
              
              for($i=0; $i<count($matches[1]); $i++) {	
                  list($id, $style, $width, $height, $comments, $float, $link) = split(":", $matches[1][$i], 7); 
                  echo "<br><b>id:$id<br>style:$style<br>width:$width<br>height:$height<br>comments:$comments<br>float:$float<br>link:$link</b><br>"; 
              } 
              ?>
              

              print_r($matches[1]); get:

              Array
              (
                  [0] => 2265:border:150::1:0:1
                  [1] => 2266:border:150::1:0:1
                  [2] => 2269:border:150::1:0:1
              )
              

                Yeah; sorry if I sounded a bit abrupt, there. I really did have a horrible http client. I saw I'd made that typo and edited the post. Every linebreak vanished from the text in the process so I had to put them back in. Then I saw another problem (with my description) and edited it again. Guess what? The stupid thing cached the textarea contents from the first time I'd gone in to edit - typo and all.

                And looking at that post, it's still got those formatting errors I'd tried to fix. :mad:.

                  Write a Reply...