Thursday, September 12, 2013

How to change the text after extract it in PHP?

How to change the text after extract it in PHP?

I'm working on my website to extract the data and I want to change text I
actually want. I'm stored the website link in MYSQL database where I can
output the link in PHP and I'm using PHP DOM to extract the data. I have
extracted the text which I got "College Football "Texas Christian at Texas
Tech" LIVE " using with this code:
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'myusername');
define('DB_PASSWORD', 'mypassword');
define('DB_DATABASE', 'mydbname');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db)
{
die("Unable to select database");
}
function clean($var)
{
return mysql_real_escape_string(strip_tags($var));
}
$channels = clean($_GET['channels']);
$id = clean($_GET['id']);
if($errflag)
{
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
echo implode('<br />',$errmsg_arr);
}
else
{
$insert = array();
if(isset($_GET['channels']))
{
$insert[] = 'channels = \'' . clean($_GET['channels']) .'\'';
}
if(isset($_GET['id']))
{
$insert[] = 'id = \'' . clean($_GET['id']) . '\'';
}
if($channels && $id)
{
$qrytable1="SELECT id, channels, links FROM tvguide WHERE
channels='$channels' && id='$id'";
$result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br
/>' . mysql_error());
while ($row = mysql_fetch_array($result1))
{
$links = $row['links'];
include ('simple_html_dom.php');
$html = file_get_html($links);
$title1 = $html->find('a[id=rowTitle1]', 0); // with this
echo $html->find('li[id=row1-3]', 0)->plaintext;
echo "<BR></BR>";
}
mysql_close($link);
}
}
?>
Here's the HTML source after I extract it:
7:30 PM College
Football
"Texas Christian at Texas Tech"

LIVE
<BR></BR>
I can see in the HTML source that there are long space which I want to get
rid it and I also want to ignore the time including AM and PM.
I want to change in the HTML source from this:
7:30 PM College
Football
"Texas Christian at Texas Tech"

LIVE
<BR></BR>
to this:
<span id='title1'>College Football: Texas Christian at Texas Tech -
LIVE</span><br></br>
Could you please tell me how I can change the text I want using my current
code?

No comments:

Post a Comment