vault backup: 2024-10-16 09:12:37
This commit is contained in:
46
Client Server Systems/Week 3/workshop3/strings.php
Normal file
46
Client Server Systems/Week 3/workshop3/strings.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Train Listings</title>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Price</th>
|
||||
</tr>
|
||||
<?php
|
||||
$url = "http://www.classifiedsteam.co.uk/index.php?page=search&sCategory=10";
|
||||
$string = file_get_contents($url);
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadHTML($string);
|
||||
$xpath = new DOMXPath($dom);
|
||||
$titles = $xpath->query("//a[contains(@class, 'title')]");
|
||||
$prices = $xpath->query("//span[contains(@class, 'currency-value')]");
|
||||
for ($i=0; $i<$titles->length; $i++) {
|
||||
$title = $titles->item($i)->textContent;
|
||||
$link = $titles->item($i)->getAttribute('href');
|
||||
$price = $prices->item($i)->textContent;
|
||||
echo "<tr>\n";
|
||||
echo "<td><a href='$link' title='$title'>$title</a></td>\n";
|
||||
echo "<td>$price</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</body>
|
||||
<style>
|
||||
html {
|
||||
font-family: "DejaVu Sans";
|
||||
}
|
||||
table, td, th {
|
||||
border: 1px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td, th {
|
||||
padding: 8px 6px 8px 6px;
|
||||
}
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
</html>
|
Reference in New Issue
Block a user