Jump to content
php.lv forumi

Regulārā izteiksme


Jackal

Recommended Posts

Ar regulārajām izteiksmēm esmu darbijies ļoti maz, tāpēc nevaru uzraktīt vienkāršu izteiksmi :(.

 

Kods

$content = "
<div>
<div class=\"post\">1<div class=\"bottom\"></div>
<div class=\"post\">2<div class=\"bottom\"></div>
<div class=\"post\">3<div class=\"bottom\"></div>
<div class=\"post\">4<div class=\"bottom\"></div>
<div class=\"post\">5<div class=\"bottom\"></div>
</div>
";


preg_match_all("/<div class=\"post\">(.*)<div class=\"bottom\"><\/div>/s", $content, $array);

print_r($array);

 

Izvada

Array
(
[0] => Array
	(
		[0] => <div class="post">1<div class="bottom"></div>
<div class="post">2<div class="bottom"></div>
<div class="post">3<div class="bottom"></div>
<div class="post">4<div class="bottom"></div>
<div class="post">5<div class="bottom"></div>
	)

[1] => Array
	(
		[0] => 1<div class="bottom"></div>
<div class="post">2<div class="bottom"></div>
<div class="post">3<div class="bottom"></div>

<div class="post">4<div class="bottom"></div>
<div class="post">5
	)

)

 

Tas nav gluži tas ko man vajadzēja. Gribēju, lai šis (<div class=\"post\">1<div class=\"bottom\"></div>) tiek ņemts katrs atsevišķi. Ir vajadzība dabūt ārā tos skaitļus, kas atrodas starp <div class="post"> un <div class="bottom"></div>.

 

Kā parezi būtu jāraksta šī regulārā izteiksme?

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...