Main

programación Archives

Agosto 5, 2004

Parsear la web para cambiar codigos ASCII a HTML

Como soy un paquete, y no me se los codigos html necesarios
para los posts, y los posts son archivos ascii (txt),
me he currado un mini script para parsearlos y que la web
siga pasando el validator de w3c:

# shell script para hacerlo en todo mi directorio /wiki:
for i in `find . -iname "*.txt"`; do
dat=`ls -l --time-style=+%Y%m%d%H%M $i | awk '{ print $6 }'`
cat $i | wraphtml.pl > $i.new.txt
touch -t $dat $i.new.txt; mv $i $i.orig
done

# perl que realmente parsea:
wraphtml.pl

Octubre 23, 2004

Expresiones regulares en php con preg_match

He tardado un buuuen rato en encontrar como hacer una expresion
regular en php. El problema es que con "ereg" no permite
que sean "non-greedy", y hay que utilzar la familia preg_*
Este ejemplo me ayudó bastante (en aleman):

$string = 'Dieser Satz wird fast gefressen';

// Normalzustand:
preg_match('/D.*r/', $string, $matches);
-> Dieser Satz wird fast gefr

// Einen Quantifier ungreedy gemacht:
preg_match('/D.*?r/', $string, $matches);
-> Dieser

// Greediness aller Quantifier umgeschaltet:
preg_match('/D.*r/U', $string, $matches);
-> Dieser

// Doppelt gemoppelt: Greediness umgeschaltet,
// einen Quantifier wieder zurückgeschaltet:
preg_match('/D.*?r/U', $string, $matches);
-> Dieser Satz wird fast gefr

// Bei dieser Schreibweise spielt die Greediness keine Rolle:
preg_match('/D[^r]*r/', $string, $matches);
-> Dieser

About programación

This page contains an archive of all entries posted to Alejandro Ramos :: personal webpage in the programación category. They are listed from oldest to newest.

otros is the previous category.

seguridad is the next category.

Many more can be found on the main index page or by looking through the archives.

rss
unsec dot net