Jump to content
php.lv forumi

preg_match


sandis_m

Recommended Posts

Vajag izdabūt vērtību, kas ir starp []

 

$teksts = "kaut kaads teksts [1]"; 



$count = preg_match('/[(.*?)]/', $teksts, $match);
if ($count === FALSE){
echo('not found\n');
   }else {
  		echo print_r($match);
   }

 

 

 

 

Vai man vienīgajam izvada:

Array ( ) 1

 

Es nekādīgi netieku pie tās vērtības 1

$match[0],$match[1],$match[2]....

Link to comment
Share on other sites

marrtins whut?

 

 

<?
$matches = array();
$str = 'kaut kaads teksts [1] kaut kaads teksts [2] kaut kaads teksts [3]';
preg_match_all('/\[(.*)\]/U', $str, $matches);
print_r($matches);
/*

Array
(
   [0] => Array
       (
           [0] => [1]
           [1] => [2]
           [2] => [3]
       )

   [1] => Array
       (
           [0] => 1
           [1] => 2
           [2] => 3
       )

)
*/
?>

Edited by marcis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...