HTML , PHP search box Help - php

How do i define the search box as VIN , so the value in my search field is sent to the php code $VIN which then retrieves it from the database.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Victorian Car Imports</title>
</head>
<body body bgcolor= "#000000">
<table width="1359" height="1028" border="0" bgcolor="#000000" bg>
<tr>
<td width="111" height="120"><img src="Logo.png" width="111" height="120" /></td>
<td width="1238"><img src="banner.jpg" width="720" height="94" align="middle"/></td>
</tr>
<tr>
<td height="780" valign="top"><a href="index.html">
<img src="Home.png" width="100" height="35" border="0"/></a> <br/> <p>
<img src="cars.png" border="0" width="100" height="35" /> <br/>
<p>
<img src="FAQ.png" border="0" width="100" height="35" /> <br/> <p>
<img src="Order_form.png" width="100" height="35" border="0" /> <p>
<img src="Contact_us.png" width="100" height="35" border="0" /></td>
<td font color= "#FFFFFF" BODY TEXT="#FFFFFF" valign="top" ><font color="#FFFFFF" >
<form name="search" action="http://www.deakin.edu.au/~sjrem/ssss.php" method="post">
<h2> Search for a car of your choice </h2>
<?php
$VIN = $_request ["search"]
?>
<p>
<table border="0">
<tr>
<td><input type="text" name="search" /> </td>
</tr>
</table>
<p>
<input type="submit" name="action" value="search" />
</FORM>
<p>
1) This skyline R32 GTR has a low 22000K's on the clock. It has been taken car of very well. It is a 1992 model which consists of a immaculate interior and a manual gearbox. It comes equipped with Air Conditioner, Alloy Wheels, Power Steering, Power Windows and a stereo system. <p> $22000 Complied
<p>
<p><img src="R32_GTR_Front.jpeg" width="320" height="240" /><img src="R32_GTR_Rear.jpeg" width="320" height="240" />
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/nissan/skyline+gt-r/7898243/photo/?sid=300&pn=4 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/nissan/skyline+gt-r/7898243/photo/?sid=300&pn=0 -->
<p> 2) As new 2002 Nissan Silvia S15. 15000 Genuine K's with log books. This prestige car, come with Air Conditioner, Alloy Wheels, Power Steering, Power Windows, Turbo. This is a clean unmodified Silvia. Its one of a kind these days. It has been driven by our buyers in Japans, and the all clear has been given. So what are you waiting for? <p> $20000 including on road costs <p>
<img src="Silvia_front.jpeg" width="374" height="294" /><img src="Silvia_rear.jpeg" width="390" height="295" /> <p>
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/nissan/silvia/7896477/photo/?sid=300&pn=1 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan car/nissan/silvia/7896477/photo/?sid=300&pn=0 -->
3) Brand New Nissan Skyline R35 GTR. This GTR is straight from the Nissan Factory in Japan. It is a 3.8 Ltr, Right hand drive, Gun metal grey in colour. It has a manual gearbox with 6 speed control. This performance car has 320kw at all four wheels and with that comes, traction control, abs brakes, driver, passenger and side air bags, power steering, and a alarm system. Contact us, if you would like any more information. $180000 Deliverd to your door step.
<p><img src="R35_front.jpg" width="384" height="284" /><img src="R35_rear.jpg" width="360" height="285" />
<p>
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/nissan/nissan+gt-r/7901460/photo/?sid=300&pn=2 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/nissan/nissan+gt-r/7901460/photo/?sid=300&pn=0 -->
4) This 2005 Subaru Impreza arrived last week. It is one of our AWD turbo vechicles. It sports a powerful 180kw, and handles like a dream. The body is staight, and the paint is immaculate. It comes with 12 months rego, $17999
<p><img src="subaru_front.jpg" width="384" height="284" /><img src="subaru_rear.jpg" width="360" height="285" />
<p>
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/subaru/impreza/7904397/photo/?sid=300&pn=4 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/subaru/impreza/7904397/photo/?sid=300&pn=0 -->
5) Mitsubishi Evolution 2006. This car is scheduled to arrive in Victoria in two weeks. It is All wheel drive sports car, sporting a 210 kw engine. It has all the safety features, such as airbags, traction control, ABS brakes, and power steering. This is a car which will never disappoint. $35000 including all on road costs.
<p><img src="mitsubishi_front.jpeg" width="384" height="284" /><img src="mitsubishi_rear.jpeg" width="360" height="285" />
<p>
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/mitsubishi/lancer+evolution+ix+mr/7901029/photo/?sid=300&pn=2 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/mitsubishi/lancer+evolution+ix+mr/7901029/photo/?sid=300&pn=0 -->
6) Toyota Chaser 1996. Boasting many electric features, Power windows, Power mirrors, Heated seats, and HID lights. This is a car, which looks like a normal family car, but has the grunt when the power is needed. We need this car moved fast, due to our next shipment coming in September. Priced to sell! $10 999
<p><img src="chaser_front.jpg" width="384" height="284" /><img src="chaser_rear.jpg" width="360" height="285" />
<p>
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/toyota/chaser/7846594/photo/?sid=300&pn=0 -->
<!-- Reference: http://www.tradecarview.com/used_car/japan%20car/toyota/chaser/7846594/photo/?sid=300&pn=2 -->
</FONT>
</tr>
<tr>
<td width="111" height="120">row 2 cell 3</td>
<td width="1238"><FONT color="#FFFFFF" >©Deakin University, School of Information Technology. This web page has been developed as a student assignment for the unit SIT104: Introduction to Web Development. Therefore it is not part of the University's authorised web site. DO NOT USE THE INFORMATION CONTAINED ON THIS WEB PAGE IN ANY WAY."</FONT>
</td>
</tr>
</table>
</body>
</html>

first your searchbox:
<input type="text" value="" name="vin" />
then in your php code:
$vin = mysql_real_escape_string($_POST['vin']);
//then do your query with $vin

Related

PHP Variable Session Code Not Working

All pages on my bosses website initiate sessions, there is a variable on the property pages that is defined (or redefined) each time a user visits one. That variable is supposed to carry over to the contact page, where it gets inserted into the PHP contact form and sent along in an email to my boss, so that he knows which property people are contacting him about.
Here is the code I use to define the variable:
$_SESSION['property'] = "55-scholard-ph5";//Set Property Name
I have a generic PHP contact form I'm using that works fine, I also have
<?php // Start the session
session_start(); ?>
at the beginning of every page. This solution was working for about a month, but now it doesn't insert that variable.
Here is the complete HTML page code:
<!--FORM SESSION CODE-->
<?php
// Start the session
session_start();
?>
<!--FORM SESSION CODE-->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1100">
<title>Boris Kholodov · 55 Scollard, Penthouse 5 · Toronto, Canada</title>
<meta name="description" content="View 55 Scollard, Penthouse 5 at Boris Kholodov's real estate website.">
<link rel="stylesheet" type="text/css" href="../design.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="../javajq/jquery.touchslider.min.js"></script>
<script>
jQuery(function($) {
$(".touchslider").touchSlider({container: this,
duration: 800, // the speed of the sliding animation in milliseconds
delay: 5000, // initial auto-scrolling delay for each loop
margin: 3, // borders size. The margin is set in pixels.
mouseTouch: true,
namespace: "touchslider",
next: ".touchslider-next", // jQuery object for the elements to which a "scroll forwards" action should be bound.
pagination: ".touchslider-nav-item",
currentClass: "touchslider-nav-item-current", // class name for current pagination item.
prev: ".touchslider-prev", // jQuery object for the elements to which a "scroll backwards" action should be bound.
autoplay: true, // Activate auto-scrolling, choose either "true" or "false"
viewport: ".touchslider-viewport"});
});
</script>
</head>
<body bgcolor="#fafbff">
<!--FORM ADDRESS CODE-->
<?php
$_SESSION['property'] = "55-scholard-ph5";//Set Property Name
?>
<!--FORM ADDRESS CODE-->
<?php include('../navigation.html');?>
<!-- MAIN CONTENT -->
<div id="page-wrap">
<!--JAVASCRIPT DISABLED NOTIFICATION-->
<noscript>
<?php include('../noscript.html');?>
</noscript>
<!---------------------------------------- MOBILE SLIDER ---------------------------------------->
<div class="touchslider hideslide" style="text-align: center;">
<div class="touchslider-viewport" style="width:1000px; height:550px; overflow:hidden; position: relative;"><div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/1.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/2.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/3.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/4.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/5.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/6.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/7.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/8.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/9.jpg" class="round" width="1000" height="550" /></div>
<div class="touchslider-item"><img src="images/55-scholard-ph5/10.jpg" class="round" width="1000" height="550" /></div>
</div>
</div>
<br /><br />
<!---------------------------------------- LEAVING FOR NOW, BUT DONT NEED IT ---------------------------------------->
<div style="text-align:center; height:5px; width: 1000px; position: relative;">
<span class="touchslider-prev" style="cursor:pointer; z-index: 40;"><span class="prevbutton"></span></span>
<span class="touchslider-next" style="cursor:pointer; z-index: 40;"><span class="nextbutton"></span></span>
</div>
</div>
<!---------------------------------------- DESKTOP SLIDER ---------------------------------------->
<div id="container" class="hidephone" >
<ul>
<li><img src="images/55-scholard-ph5/1.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/2.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/3.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/4.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/5.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/6.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/7.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/8.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/9.jpg" class="round" width="1000" height="550" /></li>
<li><img src="images/55-scholard-ph5/10.jpg" class="round" width="1000" height="550" /></li>
</ul>
<span class="button prevButton"></span>
<span class="button nextButton"></span>
</div>
<img src="images/spacer.gif" class="hidephone" />
<hr class="purple">
<br />
<!----------------------------------------MAIN INFO AREA-------------------------------------->
<article>
<section>
<div class="lefttextbig">
<header>
<h1 class="black cursive">Luxury Penthouse at the Four Seasons</h1>
<br />
<h2 class="black">$1,950,000 · 55 Scollard, Penthouse 5</h2>
</header>
<p class="black">
<br />
<span class="subtitle">CANADA'S MOST PRESTIGIOUS ADDRESS </span> Yorkville. Bloor. Four Seasons. Everyone knows. This is the most prestigious and coveted address in Canada. Luxurious, stylish, seductive, the new Four Seasons Hotel Toronto has already established itself as Toronto’s most famous meeting place. Its architectural pedigree, its personality and its name have successfully attracted those from Toronto and those from abroad.
<br /><br />
<span class="subtitle">ONLY THE BEST</span> Designed by architectsAlliance in collaboration with Page & Steele this hotel condo development demonstrates a contemporary design paired with a level of elegance that will satisfy the most discerning purchaser. The private residences offer the best in design and service.
<br /><br />
<span class="subtitle">360 DEGREE LUXURY</span> Penthouse 5 is a luxuriously finished residence, measuring 1265 precious square feet, offering you 11-foot ceilings and stunning views from floor-to-ceiling windows throughout. This suite is bright, impressive, modern, yet elegant. The layout features a discreet entrance area, an open living area, split bedrooms, 2 full baths and a 20ft balcony.
<br /><br />
<span class="subtitle">ALL YOU COULD ASK FOR — AND THEN SOME</span> The east tower is a private, exclusive, resident-only building. Its owners enjoy privacy coupled with easy access to all the benefits of Four Season living, including access to hotel amenities, facilities and services. Just steps away from five-star Yorkville shops and restaurants, and central Toronto metro stations.
<br /><br />
To schedule a viewing contact Boris Kholodov.<br /><br />
</p>
<hr class="purple">
<br /><br />
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2885.828667395075!2d-79.3884502!3d43.672532999999994!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x882b34aedb4fae43%3A0xedbc5eb829dd0221!2s55+Scollard+St%2C+Toronto%2C+ON+M5R!5e0!3m2!1sen!2sca!4v1427829323609" width="650" height="350" frameborder="0" style="border:0"></iframe>
</div>
</section>
<!----------------------------------------MAIN INFO AREA-------------------------------------->
<!----------------------------------------DETAILED INFO---------------------------------------->
<section>
<div class="rightinfo">
<!-- Boris's Photo, Title and Contact Info-->
<?php include('boris-info.html');?>
<!-- <hr class="purple">
<p class="small">
<span class="italic">Open House Times:</span><br />
Sat 28<sup>th</sup> / 2:30pm–4:30pm<br />
Sun 1<sup>st</sup> / 2:30pm–4:30pm
</p> -->
<hr class="purple">
<a href="listing-book.php" style="text-decoration: none;">
<div class="purpleb round formstyle bgcolor sendform" style="
padding: 15px 15px 8px 15px;
width: 210px;
text-align: center;">
<span class="parastyle black" style="font-weight: normal;
letter-spacing: 0.1em;">
BOOK A SHOWING
</span>
</div>
</a>
<hr class="purple">
<a href="images/55-scholard-ph5/55-scholard-ph5-floorplan-boris.pdf" style="text-decoration: none;" target="_blank">
<div class="purpleb round formstyle bgcolor sendform" style="
padding: 15px 15px 8px 15px;
width: 210px;
text-align: center;">
<span class="parastyle black" style="font-weight: normal;
letter-spacing: 0.1em;">
VIEW FLOORPLAN
</span>
</div>
</a>
<hr class="purple">
<a href="listing-contact.php" style="text-decoration: none;">
<div class="purpleb round formstyle bgcolor sendform" style="
padding: 15px 15px 8px 15px;
width: 210px;
text-align: center;">
<span class="parastyle black" style="font-weight: normal;
letter-spacing: 0.1em;">
CONTACT BORIS
</span>
</div>
</a>
<hr class="purple">
<p class="small">
<span class="italic">Type:</span>
Downtown Penthouse
<br />
<span class="italic">Neighbourhood:</span>
Yorkville
<br />
<span class="italic">Square Footage:</span>
1265<sup>sf</sup> + Balcony
<br />
<!--<span class="italic">Lot Size:</span>
33<sup>ft</sup> × 128<sup>ft</sup>
<br /> -->
<span class="italic">Property Tax:</span>
$15,266 for 2014
<br />
<span class="italic">Bedrooms:</span>
2
<br />
<span class="italic">Washrooms:</span>
2
<br />
<span class="italic">Parking:</span>
1 Owned Underground
</p>
<hr class="purple">
<p class="small">
<span class="italic">Inclusions:</span>
<ul >
<li class="small">Miele Gas Cooktop and Oven, Sub-Zero Fridge, Panasonic Microwave, Dishwasher, Stacked Washer/Dryer</li>
<li class="small">All Existing Light Fixtures</li>
<li class="small">All Existing Window Coverings</li>
</ul>
<hr class="purple">
<p class="small">
To inquire further about this property please contact Boris.
</p>
</div>
</section>
<!----------------------------------------DETAILED INFO---------------------------------------->
</article>
<?php include('../footer.html');?>
</div>
<!-- MAIN CONTENT -->
<script src="../javajq/jquery-1.11.2.min.js"></script>
<script>
$(window).load(function(){
var pages = $('#container li'), current=0;
var currentPage,nextPage;
var timeoutID;
var buttonClicked=0;
var handler1=function(){
buttonClicked=1;
$('#container .button').unbind('click');
currentPage= pages.eq(current);
if($(this).hasClass('prevButton'))
{
if (current <= 0)
current=pages.length-1;
else
current=current-1;
}
else
{
if (current >= pages.length-1)
current=0;
else
current=current+1;
}
nextPage = pages.eq(current);
currentPage.fadeTo('slow',0.3,function(){
nextPage.fadeIn('slow',function(){
nextPage.css("opacity",1);
currentPage.hide();
currentPage.css("opacity",1);
$('#container .button').bind('click',handler1);
});
});
}
var handler2=function(){
if (buttonClicked==0)
{
$('#container .button').unbind('click');
currentPage= pages.eq(current);
if (current >= pages.length-1)
current=0;
else
current=current+1;
nextPage = pages.eq(current);
currentPage.fadeTo('slow',0.3,function(){
nextPage.fadeIn('slow',function(){
nextPage.css("opacity",1);
currentPage.hide();
currentPage.css("opacity",1);
$('#container .button').bind('click',handler1);
});
});
timeoutID=setTimeout(function(){
handler2();
}, 8000);
}
}
$('#container .button').click(function(){
clearTimeout(timeoutID);
handler1();
});
timeoutID=setTimeout(function(){
handler2();
}, 8000);
});
</script>
<!--GOOGLE TRACKING-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61408930-1', 'auto');
ga('send', 'pageview');
</script>
<!--GOOGLE TRACKING-->
</body>
</html>
Here is the contact form code referenced in a separate PHP document:
<?php
session_start();
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Please use the form.
echo "Error, please return to last page.";
}
$property = $_SESSION['property'];
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$tel = $_POST['tel'];
$message = $_POST['message'];
$spambot = $_POST['spambot'];
if ($spambot != 'Yes') {
$spambot = 'No';
}
//Validate first
if($spambot == 'No')
{
echo "Please go back and check the 'I'm not a Spambot' box.";
exit;
}
if(empty($name)||empty($visitor_email)||empty($tel))
{
echo "Name, email and phone number are mandatory.";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
// Email information
$email_from = "boris#agentboris.com";
$email_subject = "Real Estate";
$email_body =
"PROPERTY: $property \n \n".
"NAME: $name\n \n".
"MESSAGE:\n
$message \n \n ".
"PHONE NUMBER: $tel\n \n".
"EMAIL: $visitor_email\n \n".
$to = "boris#agentboris.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: ../contact/thankyou.php');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
What is the problem?
You can experience the contact form by visiting this property page and clicking on any of the contact links. Please enter "community test" in the body of the form so that my boss knows its not a real client.
http://agentboris.com/listings/92-park.php
If you don't mind, I'd like to advise you not to use Session to do that, many users (like me) open multiple pages before viewing, so your property will get just the last one, sending the wrong property to your boss. Instead, you could pass this info via URL variable, changing the href property of the contact button to something like: http://agentboris.com/listings/listing-contact.php?property=55-scholard-ph5 on each page, and use the PHP $_GET["property"] in your contact's PHP code. You could use the contact form on each page too.
About the doubt of the solution stop working, make sure you aren't using #session_destroy() anywhere, neither resetting it elsewhere, sometimes I do something like: if (!$_SESSION["property"] = "") and in reality I'm resetting it to "". Certainly you are starting the session in the contact's page, right after <?php... you have to start the session to get the variable ok.
Hope it help you! Regards!
PS. you have a beautiful website!

How extract data from html using php

I have fetch this html code.
<td valign="top" style="padding:3px">
<p>
<b>Release Year: </b>2005
<br />
<b>
Genre:
<a href=/genres/Animation>Animation</a>,
<a href=/genres/Comedy>Comedy</a>
</b>
<br />
<b>External Links: </b>
IMDB
<br />
<b>No. of episodes: </b> 23 episodes
<br />
<b>Latest Episode With Links: </b>
<a title="Watch American Dad! Latest Episode (American Dad! Season 1 Episode 23)" href="/episode/american_dad_s1_e23.html">
Season 1 Episode 23 Tears of a Clooney (14/05/2006)
</a>
<br />
<div style="float: left; height: 30px; overflow: hidden; width: 100px;">
<div class="fb-like" data-href="http://watchseries.ag/season-1/american_dad" data-send="false" data-layout="button_count" data-show-faces="false"></div>
</div>
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<br clear="all" />
<b>Description :</b> The random escapades of Stan Smith, an extreme right wing CIA agent dealing with family life and keeping America safe, all in the most absurd way possible.<br>
</p>
</td>
I want only this information from above html code using php.
Only want 3 things
1.Release Year
2. Imdb Link
3. Genre
array(
'release_year'=>2005,
'imbd_link'=>'http://www.imdb.com/title/tt0397306/',
'genre'=> array(
'Animation',
'Comedy',
)
);
I have also created php function which filter html code and return me array but its not give the result like above i showed the array() its give me this result
Output
Array
(
[release year] => 2005Genre
)
function
function do_html_array($td,$dlm='<br>'){
if(!empty($td)){
$td = html_entity_decode($td);
$td = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $td);
$html_array = explode($dlm,$td);
$html_key_array = array();
foreach($html_array as $key=>$html){
$html = explode(':',trim(strip_tags($html)));
if(trim($html[0])!=''){
if(count($html)<1) $html[1] = '';
if(strtolower(trim($html[0]))=='description') $html[1] = str_ireplace('[+]more','',$html[1]);
$html_key_array[strtolower(trim($html[0]))] = trim($html[1]);
switch(trim(strtolower($html[0]))){
case'external links':
preg_match_all('~<a\s+.*?</a>~is',$html_array[$key],$html_key_array['imdb_link']);
break;
case'genre':
preg_match_all('~<a\s+.*?</a>~is',$html_array[$key],$html_key_array['genre_link']);
break;
// further define here...
}
}
}
return $html_key_array;
}
return false;
}

how to edit <img> tag in the string

<p> </p>
<p><img src="../../../..//js/uploads/images/selva.png" alt="" /></p>
<p>we are checkng our website</p>
<p>kfoaskf</p>
<p>asldfjas</p>
<p>jasdklfk'sd</p>
<p><img src="../../../..//js/uploads/images/images.jpg" alt="" /></p>
This is my string values. i need to change only this
<img src="../../../..//js/uploads/images/images.jpg"> to
<img src="js/uploads/images/images.jpg">
for every image ,i need to modify the path.
how to do it? and my string values also differ at every time
Try this bro
$str='<p> </p>
<p><img src="../../../..//js/uploads/images/selva.png" alt="" /></p>
<p>we are checkng our website</p>
<p>kfoaskf</p>
<p>asldfjas</p>
<p>jasdklfk\'sd</p>
<p><img src="../../../..//js/uploads/images/images.jpg" alt="" /></p>';
echo str_replace("../../../..//js/uploads/images/images.jpg","/js/uploads/images/images.jpg",$str);

XPath & PHP: Matching text after a <br>

I'm trying to sort through a large list of video links. I'm wanting to sort them by 2014, 2013, 2012, and so on, so as an example, I'm after an XPath query to get the '2014', and retrieve all the movies that match 2014.
My effort: Tried matching text and checking for text after <br>, but that retrieves every single thing after every <br> in the document!
Maybe something with a text match as well? I.e. after <br> and text() = '2014 - '?
<td>
<table>
<tbody>
<tr>
<td>
<span>
<br>
2014 -
<a id="3447" class="tippable" href="www.examplemovie.com" style="color:#fff">The MovieName1</a>
<br>
2014 -
<a id="3595" class="tippable" href="www.examplemovie.com" style="color:#fff">MovieName2</a>
<br>
Thanks!!
I would suggest trying
//a[preceding-sibling::node()[1][contains(self::text(), '2014')]]
This will actually select the a elements for 2014, which I think is what you're actually after.
You can use the following xpath expression:
//a[contains(preceding-sibling::text()[1], "2014")]
This basically means: give me all of the a tags that has a text before it, containing 2014.
Demo:
Imagine you have the following index.html file:
<table>
<tbody>
<tr>
<td>
<span>
<br/>
2014 -
<a id="3447" class="tippable" href="www.examplemovie.com" style="color:#fff">The MovieName1</a>
<br/>
2014 -
<a id="3595" class="tippable" href="www.examplemovie.com" style="color:#fff">MovieName2</a>
<br/>
</span>
</td>
</tr>
</tbody>
</table>
Then, here is the output of xmllint xpath test:
$ xmllint index.html --xpath '//a[contains(preceding-sibling::text()[1], "2014")]'
<a id="3447" class="tippable" href="www.examplemovie.com" style="color:#fff">The MovieName1</a>
<a id="3595" class="tippable" href="www.examplemovie.com" style="color:#fff">MovieName2</a>

Regex to replace url in html page

i have an html page
<tr>
<td rowspan="7">
<a href="http://www.link1.com/" style="text-decoration: none;">
<img src="image1.jpg" width="34" height="873" alt="" style="display:block;border:none" />
</a>
</td>
<td colspan="2" rowspan="2">
<a href='http://www.link1.com/test.php?c=1'>
<img src="image1.jpg" width="287" height="146" alt="" style="display:block;border:none" />
</a>
</td>
<td colspan="2" rowspan="2">
<a href='http://www.url.com/test.php?c=1'>
<img src="image1.jpg" width="287" height="146" alt="" style="display:block;border:none" />
</a>
</td>
I want to replace all url in href by mytest.com?url=$link
I try with :
$messaget = preg_replace('/<a(.*)href="([^"]*)"(.*)>/','mytest.com?url=$2',$messaget);
This may help you in the short run:
preg_replace('/<a (.*)href=[\'"]([^"]*)[\'"](.*)>/', '<a $1href="mytest.com?url=$2"$3>', $messaget);
In your regex you were using href="...", that is, double quotes, but in your HTML you have a mixture of both double and single quotes.
And in the replacement string you forgot to include $1 and $3.
That said, DO NOT use regex to parse HTML. The answer by #BenLanc below is better, use that instead. Read the link he posted.
Don't use regex on HTML, HTML is not regular.
Assuming your markup is valid (and if it's not, pass it through Tidy first), you should use xpath, to grab the elements and then update the href directly. For example:
<?php
$messaget = <<<XML
<tr>
<td rowspan="7">
<a href="http://www.link1.com/" style="text-decoration: none;">
<img src="image1.jpg" width="34" height="873" alt="" style="display:block;border:none" />
</a>
</td>
<td colspan="2" rowspan="2">
<a href='http://www.link1.com/test.php?c=1'>
<img src="image1.jpg" width="287" height="146" alt="" style="display:block;border:none" />
</a>
</td>
<td colspan="2" rowspan="2">
<a href='http://www.url.com/test.php?c=1'>
<img src="image1.jpg" width="287" height="146" alt="" style="display:block;border:none" />
</a>
</td>
</tr>
XML;
$xml = new SimpleXMLElement($messaget);
// Select all "a" tags with href attributes
$links = $xml->xpath("//a[#href]");
// Loop through the links and update the href, don't forget to url encode the original!
foreach($links as $link)
{
$link["href"] = sprintf("mytest.com/?url=%s", urlencode($link['href']));
}
// Return your HTML with transformed hrefs!
$messaget = $xml->asXml();
Don't forget /m at the end of your regexp since your are using multiline source:
PHP Doc PCRE
Regex to match an url:
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
More background info

Categories