Jump to content
php.lv forumi

Regex nepilniba


Joyride

Recommended Posts

Sis kods:

 

preg_match_all('<!-- INCLUDE (.*) -->', $this->html, $matches);
echo '<pre>'; print_r($matches); echo '</pre>';

 

atgriez:

 

Array
(
[0] => Array
	(
		[0] => !-- INCLUDE header.html --
		[1] => !-- INCLUDE footer.html --
	)

[1] => Array
	(
		[0] => header.html
		[1] => footer.html
	)

)

 

Kas ir japamaina, lai Array[0][...] vertibam butu ari klat < > iekavas?

 

Pats par sevi, parsets tiek html kods.

Link to comment
Share on other sites

izmanto atdaliitaajus (delimiters). jo pregs shajaa gadiijumaa izmanto <> kaa atdaliitaajus.

izmanto piemeeram / vai # ziimes.

 

preg_match_all('/<!-- INCLUDE (.*) -->/', $this->html, $matches);

Link to comment
Share on other sites

Viena nepilniba atradas - ja kods ir sads:

 

<p><!-- INCLUDE footer --></p><p><!-- INCLUDE footer --></p>

 

tad nepareizi tiek izvadits rezultats:

 

Array
(
[0] => Array
	(
		[0] => <!-- INCLUDE footer --></p><p><!-- INCLUDE footer -->
	)

[1] => Array
	(
		[0] => footer --></p><p><!-- INCLUDE footer
	)

)

 

RegExus vel tikai macos, tapec soreiz pats netieku gala.

Link to comment
Share on other sites

×
×
  • Create New...