Menu
I want to detect all the mail adresses on a webpage and convet them on mailto/Hyperlinks and this is what I have until now, someone can give me hand please ?
_Lobo
[url]http://ch2.php.net/ereg
[code=php]<?php
function detectEmail($email)
{
return ereg(“^[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]+$”, $email);
echo $email(“<a href=’mailto:”^[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]+$”‘>””</a>”);}
?>
[code=php]<?php
$text = "Hello, this is a test to [email][email protected][/email] see if it changes all 3 of the emails. [email][email protected][/email] It also works if the same address comes along more than once.an [email][email protected][/email] though i'm not sure about what it does to <a href='mailto:[email protected]'>[email protected]</a> :-) n";
$email = $text;
// the callback function
function add_link($matches)
{
//print_r($matches); // show's array's structure
return '<a href="mailto:'.$matches[0].'">'.$matches[0].'</a>';
}
echo preg_replace_callback("/[a-z0-9]+([-_.]?[a-z0-9])+@[a-z0-9]+([-_.]?[a-z0-9])+.[a-z]{2,4}/","add_link",$text);
?>[/code]
[code=php]<head>
<style type="text/css">
table {
font-family: arial, sans-serif;
font-size: smaller;
border-collapse: collapse;
border: solid black thin;
width: 500px;
}
th,td {
margin: 0;
padding: 3px;
border: solid black thin;
}
th {
font-weight: bold;
text-align: center;
}
</style>
</head>
<body>
<?php
$email = $value;//Code added
$handle = fopen("test.csv", "r");
$data = fgetcsv($handle, 1000, ";");
# column headers from 1st row of CSV:
echo "<tr>"; // removed style attribute as $bg not defined here
foreach($data as $value)
{
echo "<th>$value</th>";
}
echo "</tr>n";
# data rows:
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if($thisRow++ % 2 == 0) // $row not defined, $thisRow is though
{
$bg = "#CCCCCC"; // added $ and ;
}
else
{
$bg = "#FFFFFF";
}
echo "<tr style='background-color: $bg'>"; // added style attribute, assumed it was meant to be here
foreach($data as $value)
{
echo "<td>$value</td>";
}
echo "</tr>n";
}
echo "</table>n";
//code added
// the callback function
function add_link($matches)
{
//print_r($matches); // show's array's structure
return '<a href="mailto:'.$matches[0].'">'.$matches[0].'</a>';
}
echo preg_replace_callback("/[a-z0-9]+([-_.]?[a-z0-9])+@[a-z0-9]+([-_.]?[a-z0-9])+.[a-z]{2,4}/","add_link",$value);
echo "<table>";
}}
?>
</body>
</html> [/code]
[code=php]<?php
$email = $value;//Code added
/* this variable is not necessary */
$handle = fopen("test.csv", "r");
$data = fgetcsv($handle, 1000, ";");
/*Open file and save contents in array $data */
# column headers from 1st row of CSV:
/* You forgot to "START" the <table> */
echo "<tr>"; // removed style attribute as $bg not defined here
foreach($data as $value)
{
echo "<th>$value</th>";
/* echo column headers */
}
echo "</tr>n";
# data rows:
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if($thisRow++ % 2 == 0) // $row not defined, $thisRow is though
{
$bg = "#CCCCCC"; // added $ and ;
}
else
{
$bg = "#FFFFFF";
}
echo "<tr style='background-color: $bg'>"; // added style attribute, assumed it was meant to be here
foreach($data as $value)
{
echo "<td>$value</td>";
/*echo values in .csv as are, without changes. */
}
echo "</tr>n";
}
echo "</table>n";
//code added
// the callback function
function add_link($matches)
{
//print_r($matches); // show's array's structure
return '<a href="mailto:'.$matches[0].'">'.$matches[0].'</a>';
}
/* It's probably better if you put this code near the top of the page. */
echo preg_replace_callback("/[a-z0-9]+([-_.]?[a-z0-9])+@[a-z0-9]+([-_.]?[a-z0-9])+.[a-z]{2,4}/","add_link",$value);
/* This outputs the $value with all the links 'fixed', I'm guessing this should be in the place of the «echo "<td>$value</td>";» instead. */
echo "<table>";
/* Start table? */
}}
?>
</body>
</html> [/code]
[i]Originally posted by _LOBO_ [/i]How can that page be completely blank? (including source)
[B]don't work sorry, take a look
http://www.nhfg-intl.com/christian/csv/csv.php [/B][/QUOTE]
[code=php]
ID;Nachname;Vorname;Ort;Land;EmailAdr
727349;Genbach;Andreas;Aachen;Deutschland;[email protected]
728283;Deleon;Giambattista;Paderborn;Deutschland;
729148;Chris;Ulrich;Rosengarten;Deutschland;[email protected]
[/code]
[code=php]
function html_activate_urls($str)
{
if(!preg_match("http://", $str)) {
$str = "http://$str";
}
// lift all links, images and image maps
preg_match_all("/<a [^>]+>.*</a>/is", $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
preg_match_all("/<map [^>]+>.*</map>/is", $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
}
preg_match_all("/<img [^>]+>/is", $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
}
$str = str_replace($replace, $search, $str);
// indicate where urls end if they have these trailing special chars
$sentinals = array("'&(quot|#34);'i", // Replace html entities
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(d+);'e");
$str = preg_replace($sentinals, "^^sentinal^^\0^^sentinal^^", $str);
$vdom = "[:alnum:]"; // Valid domain chars
$vurl = $vdom."_~-"; // Valid subdomain and path chars
//$vura = "À-ßà-ÿ!#$%&*+,;=@.".$vurl; // Valid additional parameters (after '?') chars;
$vura = "À-ßà-ÿ!#$%&*+,;=@./".$vurl; // Valid additional parameters (after '?') chars;
// insert other local characters if needed
$protocol = "[[:alpha:]]{3,10}://"; // Protocol exp
$server = "([$vurl]+[.])*[$vdom]+"; // Server name exp
$path = "(([$vurl]+([.][$vurl]+)*/)|([.]{1,2}/))*"; // Document path exp (/.../)
$name = "[$vurl]+([.][$vurl]+)*"; // Document name exp
$params = "[?][$vura]*"; // Additional parameters (for GET)
$str = eregi_replace("$protocol$server(/$path($name)?)?($params)?", "<a href="\0">\0</a>", $str); // URL into links
$str = str_replace("^^sentinal^^", '', $str);
return str_replace($search, $replace, $str);
}
[/code]
[code=php]<?php
echo "<table>";
echo "<tr>"; // removed style attribute as $bg not defined here
# data rows:
$handle = fopen("data.csv", "r");
$data = fgetcsv($handle, 1000, ";");
foreach($data as $value)
{
echo "<th>$value</th>";
}
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if($thisRow++ % 2 == 0) // $row not defined, $thisRow is though
{
$bg = "#CCCCCC"; // added $ and ;
}
else
{
$bg = "#FFFFFF";
}
echo "<tr style='background-color: $bg'>"; // added style attribute, assumed it was meant to be here
print_r($data);
$data[5] = "<a href='mailto:".$data[5]."'>".$data[5]."</a>";
foreach($data as $value)
{
echo "<td>$value</td>";
}
echo "</tr>n";
}
echo "</table>n";
?> [/code]
[code=php]
head>
<style type="text/css">
table {
font-family: arial, sans-serif;
font-size: smaller;
border-collapse: collapse;
border: solid black thin;
width: 500px;
}
th,td {
margin: 0;
padding: 3px;
border: solid black thin;
}
th {
font-weight: bold;
text-align: center;
}
</style>
</head>
<body>
<table><tr><tr style='background-color: #FFFFFF'><td><a href='mailto:'></a></td></tr>
<tr style='background-color: #CCCCCC'><td><a href='mailto:'></a></td></tr>
<tr style='background-color: #FFFFFF'><td><a href='mailto:'></a></td></tr>
<tr style='background-color: #CCCCCC'><td><a href='mailto:'></a></td></tr>
[/code]
[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>data page php</title>
<style type="text/css">
table {
font-family: arial, sans-serif;
font-size: smaller;
border-collapse: collapse;
border: solid black thin;
width: 500px;
}
th,td {
margin: 0;
padding: 3px;
border: solid black thin;
}
th {
font-weight: bold;
text-align: center;
}
</style>
</head>
<body>
<?php
echo "<table>";
echo "<tr>"; // removed style attribute as $bg not defined here
# data rows:
$handle = fopen("data.csv", "r");
$data = fgetcsv($handle, 1000, ";");
foreach($data as $value)
{
echo "<th>$value</th>";
}
$thisRow = 1;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if($thisRow++ % 2 == 0) // $row not defined, $thisRow is though
{
$bg = "#CCCCCC"; // added $ and ;
}
else
{
$bg = "#FFFFFF";
}
echo "<tr style='background-color: $bg'>"; // added style attribute, assumed it was meant to be here
//print_r($data);
$data[5] = "<a href='mailto:".$data[5]."'>".$data[5]."</a>";
foreach($data as $value)
{
echo "<td>$value</td>";
}
echo "</tr>n";
}
echo "</table>n";
?>
</body>
</html> [/code]
[CODE]ID;Nachname;Vorname;Ort;Land;EmailAdress
727349;Genbach;Andreas;Aachen;Deutschland;[email protected]
728283;Deleon;Giambattista;Paderborn;Deutschland;
729148;Chris;Ulrich;Rosengarten;Deutschland;[email protected][/CODE]
ID;Nachname;Vorname;Ort;Land;EmailAdress
0.1.9 — BETA 5.19