Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Doncrawler - filter
Pyton_000
post
Post #1





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Mam sobie HTML:

  1. <div>
  2. <div>
  3. <p>
  4. <pre>Test</pre>
  5. </p>
  6. <p>
  7. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab architecto esse harum illo iste modi mollitia obcaecati repudiandae suscipit unde! Architecto atque blanditiis dignissimos dolorem molestiae quia recusandae sunt tenetur.
  8. </p>
  9. <pre>
  10. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aliquid atque consectetur deserunt dolorem doloremque earum hic illum impedit ipsa ipsam molestias nihil non quasi quidem repellat, soluta suscipit unde.
  11. </pre>
  12. </div>
  13. </div>


Chciałbym zrobić sobie filter na 'pre' a konkretnie chcę zrobić htmlentities. Jednak nie chcę wyciągać samego pre ale "zamienić" oryginalne "pre" na przefiltrowane.

Jakiś prosty i szybki sposób?

To co mam:
  1. $crawler = new Crawler($content);
  2.  
  3. $crawler->filter('pre > code')->each(function(Crawler $node, $i) {
  4. return htmlentities($node->html());
  5. });
Go to the top of the page
+Quote Post
kpt_lucek
post
Post #2





Grupa: Zarejestrowani
Postów: 428
Pomógł: 77
Dołączył: 10.07.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Może tak?
Go to the top of the page
+Quote Post
Pyton_000
post
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Przecież to robi dokładnie to samo... tylko inaczej opakowane...

[EDITED]

Dobra, na razie nie chce mi się kombinować więc prostym i sprawdzonym sposobem dałem sobie tak:
  1. return preg_replace_callback('/(<code.*?>)(.*?)(<\/code>)/s', function ($match) {
  2.  
  3. $content = htmlentities($match[2], ENT_COMPAT | ENT_HTML401, ini_get("default_charset"), false);
  4.  
  5. return $match[1] . $content . $match[3];
  6. }, $content);


Ten post edytował Pyton_000 1.01.2016, 12:34:26
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 22:59