Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #21829
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Sandro kensan <kensan@kensan.it> |
| Newsgroups | it.comp.www.php |
| Subject | metà di un DOM: codice scritto ma è lunghissimo! |
| Date | Sun, 10 Dec 2017 14:52:59 +0100 |
| Lines | 60 |
| Message-ID | <f94shrFahlfU1@mid.individual.net> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net JQDaAIbNmUWSi29QrZVCNA19DcvX2BEt2X5r9Wp2jzXnky+pEm |
| Cancel-Lock | sha1:A0dXh9WsELgKKPcppnZHEIxJ4Yg= |
| X-Mozilla-News-Host | snews://news.individual.net:563 |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAACdQTFRF ////e3t7c5Rrc4xrc4Rza6Vaa5xja5RjY8ZCY7VKY61SWtY5Ws5COHDUbwAAASBJREFUOMt1071u gzAQAGC/wsmlSgRL50yZO2WM1CVjRRaGTH2KzJky8xQWIap1XjLzUjnzE+K7wxIS8Mnn+wGDYh0g LsNftwA6XHUIFehwAx3usABuAWJGWe0PAuIJf2PGhkXKp4gqtByoOERPNw8G9Ixhm/dbeajaA3xj o53h6GolZD14pcB9pcDQko9OQhOh6JvJ2k5iLzLdeMypRhWQt8QfWQ5mnqgt3z8U8/bJTHKdoHnN 8/P4mrtJJw22mmfeB7LAlhk2/GC7FfAYBhp2HCiJzTi/FCpYzx1MIcfw22GQUFAC6zTtKZQDK+EM UFIGpQB6XtE2CUNzMhkKv8ZJC/iPNZcKxNJWvHSj/oApuAWQ3VU3zHAGHe6gg+Pv4QkKmdrgO+XA 0gAAAABJRU5ErkJggg== |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 |
| Content-Language | it-IT |
| Xref | csiph.com it.comp.www.php:21829 |
Show key headers only | View raw
Ho scritto il codice per mettere un ads (pubblicità adsense) a metà di
un testo in html ma il codice che ne risulta è molto lungo, questo in
parole semplici il codice che ho scritto:
* una funzione che trova il testo (nodeValue) di un nodo e di tutti i
children (funzione ricorsiva)
* una funzione che Trasforma il testo html in un nodo
L'algoritmo php è questo:
1) memorizza tutti i figli di "body" dello stesso livello con la
lunghezza del testo (vedi la prima funzione) in due array
2) Trova la metà del testo e memorizza il nodo immediatamente prima
della metà, la metà del testo è basata sulla lunghezza del testo di un
nodo (ramo), vedi il punto 1)
3) Inserisce la pubblicità (una stringa html) a metà del DOM usando la
seconda funzione e insertBefore()
Esempio di html:
<p>
test<span>foo<b>bar</b></span>
</p>
prova test
<span>foo<b>bar</b></span>
test
<span>foo<b>bar</b></span>
<br>
<script>
ignored
</script>
<!-- comment is ignored -->
<p>Ciao come stai?</p>
Stringhe trovate:
string(10) "testfoobar"
string(10) "prova test"
string(6) "foobar"
-----------------------> posizione 2.5
string(4) "test"
string(6) "foobar"
string(0) ""
string(0) ""
string(0) ""
string(0) ""
string(15) "Ciao come stai?"
La metà trovata è in posizione 2.5, qui inserisce una stringa html:
<p> test<span>foo<b>bar</b></span> </p> prova test<span>foo<b>bar</b></span>
<a href="www.adsense.com">PUBBLICITÀ</a>
test<span>foo<b>bar</b></span> <br><script> ignored </script><!--
comment is ignored --><p>Ciao come stai?</p>
--
Sandro kensan www.kensan.it & www.qiqi.it geek site
Saluto gli agenti della NSA - Hello NSA - www.nsa.gov
Back to it.comp.www.php | Previous | Next | Find similar | Unroll thread
metà di un DOM: codice scritto ma è lunghissimo! Sandro kensan <kensan@kensan.it> - 2017-12-10 14:52 +0100
csiph-web