<?php namespace leer_receta;
function hogarutil( $url ) { // obtener titulo $string = file_get_contents($url) or die("No se ha podido abrir"); $title = strstr( $string, "<h1"); $title = strstr( $title, ">" ); $end_title = strpos( $title, "<" ); $title = substr( $title, 1, $end_title - 1 ); echo "titulo: " . $title . "<br/><br/>";
// obtener texto de los ingredientes $begin_ingr = strpos( $string, "Ingredientes" ); $end_ingr = strpos( $string, "Prepara" ); $ingr = substr( $string, $begin_ingr, $end_ingr - $begin_ingr ); $begin_ingr = strpos( $ingr, "s" ) + 1; $ingr = ltrim( substr( $ingr, $begin_ingr ), " :" ); echo "texto de los ingredientes:<br/><textarea name=\"code\">" . $ingr . "</textarea><br/>";
// preparar para fragmentar ingredientes $search = array( "</p>", "</li>", "<br/>"); $replace = array( "__endline__", "__endline__", "__endline__" ); $ingr = str_replace( $search, $replace, $ingr ); $ingr = strip_tags( $ingr ); $ingr = trim( $ingr ); echo "texto de los ingredientes a punto de fragmentar:<br/><textarea name=\"code\">" . $ingr . "</textarea><br/>";
// fragmentar ingredientes $array_ingr = explode( "__endline__", $ingr ); foreach( $array_ingr as $ingr ) { if( $ingr !== "" ) { echo "_".$ingr."_<br/>"; echo "_".$ingr[0]."_<br/>"; if( ctype_space( $ingr[0] ) ) echo " Es un espacio<br/>"; else echo " No es un espacio<br/>"; // ===========> aquí NO funciona echo "_".trim( $ingr )."_<br/>"; } }
echo "<br/>"; // ====> aquí funciona echo trim( " a ver si funciona "). "<br/>"; }
//hogarutil("http://www.hogarutil.com/comunidad/recetas/postres/201308/bombones-mascarpone-chocolate-blanco-frutos-4903.html"); //hogarutil("http://www.hogarutil.com/comunidad/recetas/postres/201303/bombones-chocolate-rellenos-75.html"); hogarutil("http://www.hogarutil.com/comunidad/recetas/postres/201307/flan-chocolate-blanco-lagrimas-caramelo-4779.html") ?> |