Foros aprenderaprogramar.com

Aprender a programar => C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más => Mensaje iniciado por: paramonso en 28 de Julio 2017, 20:44

Título: Php Lectura de archivos fichero file_get_contents y nl2br substr_count. CU00838B
Publicado por: paramonso en 28 de Julio 2017, 20:44
Hola. >:(
Aquí dejo el Ejercicio CU00838B del tutorial básico de programación web con PHP desde cero.

Código: [Seleccionar]

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>PHP Desde cero aprenderaprogramar.com</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 1.27" />
 
</head>

<body>
<h1>Ejercicio 38(CU000838B) PHP </h1>


<?php
 
echo ' <div>';
print 
'<h2>Extraer código fuente de página web con PHP. <br/>
Leer archivos completos: file_get_contents y nl2br (CU00838B)</h2>'
;
 
echo 
"<h1>Ejercicio 1</h1>";
$texto file_get_contents("miArchivoDePrueba.txt");
echo  
nl2br($texto);

echo 
"<h1>Ejercicio 2</h1>";
//Ejercicio 2

$pagina = array('http://www.ite.educacion.es/',
'http://es.lipsum.com/',
'http://pagoranking.com/');
$Caracter="h1";
for (
$i=0$i<3;$i++)
{
cogerCodigo ($pagina[$i],$Caracter);
}
echo 
'<br/>';

echo 
'</div>';

function 
cogerCodigo($pag,$Car)
{

$Linea=file_get_contents($pag);
echo 
"El caracter $Car aparece &nbsp;".substr_count($Linea,$Car)."&nbsp;Veces en $pag <br/>";
}
?>


</body>

</html>



Hasta las bases de datos
 ;)
Título: Re:Ejercicio 38(CU000838B) PHP
Publicado por: pedro,, en 29 de Julio 2017, 12:41
Buenas paramonso. Todo bien. Saludos. ;D