Cannot get get right value with XPath - php

I'm using a src which collects data and works as an API.
The website it takes info from had been redone and some stuff work, some don't.
PHP:
protected $namexpath = ".//h1[contains(#itemprop,\"name\")]/a";
Works with HTML Source:
<h1 itemprop="name" class="fn itemTitle">
<a title="https://www.paginegialle.it/altopascio-lu/lotto-ricevitorie/lucky-planet-duro-anastasia-tabaccheria-ricevitori" href="https://www.paginegialle.it/altopascio-lu/lotto-ricevitorie/lucky-planet-duro-anastasia-tabaccheria-ricevitori">
Lucky <strong>Planet</strong> - Duro Anastasia <strong>Tabaccheria</strong> Ricevitoria Lotto
</a>
</h1>
But this is not working:
PHP:
protected $telephonexpath = ".//div[#class=\"hidden-phone-elem visiblePhone\"]/span";
HTML Source:
<section itemscope="" itemtype="https://schema.org/LocalBusiness" class="vcard listElement flFree " data-user="teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" data-id="4" data-fl_free="true" data-cd_opec="GU01WAAW" data-cd_aggregazione="23787370" data-cd_id_sede="E57901ED-8833-A2AD-E040-A8C08D264C56">
<div class="container">
<div class="row">
<div class="col contentCol">
<header>
<div class="tabletOnlyBadge">
</div>
<h1 itemprop="name" class="fn itemTitle">
<a title="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda">
<strong>Planet</strong> Cafe' di Tozzi Iolanda
</a>
</h1>
<span class="itemSubtitle">
</span>
<div>
<span class="itemAddress">
<span class="adr" itemprop="location" itemscope="" itemtype="https://schema.org/Place">
<div class="street-address">
<span>105, Via Roma</span> -
<span class="postal-code">81030</span>
<span class="locality">Teverola</span> <span class="region">(CE)</span>
</div>
<div style="display: none;">
<span>40.99494</span>
<span>14.2077</span>
</div>
</span>
</span>
</div>
</header>
<div>
<div class="hidden-phone-wrapper">
<span class="custom-label"></span>
<div class="hidden-phone-elem">
<div class="btn btn-yellow btn-show-phone" data-pag="mostra telefono" data-context="listing">
<span>MOSTRA TELEFONO</span>
</div>
<div class="btn btn-hidden-phone">
<span class="phIco "></span>
<span class="phone-label">081 5034556</span>
</div>
</div>
</div>
<div class="itemGeoLinks">
<ul>
</ul>
</div>
<div class="itemPayoff">
<p class="payoff-title">
<a class="cat" href="//www.paginegialle.it/ricerca/cat/008647000" rel="nofollow"><strong>Tabacchi</strong>, sigarette e sigari - produzione e commercio</a>
</p>
<p itemprop="description" class="payoff-txt"></p>
</div>
<div class="itemInfoTags">
</div>
</div>
</div>
<div class="col-3 logoCol">
<div class="itemRating">
<a rel="nofollow" href="//www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda/commenti#scrivi">
<ul class="stars">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<span class="label scriviRecensione">Scrivi una recensione</span>
</a>
</div>
<figure class="itemLogo">
<div class="img-container-ext">
<div class="img-container-int">
<a href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" title="Dettagli azienda">
<img itemprop="image" alt="Planet Cafe' di Tozzi Iolanda" title="Planet Cafe' di Tozzi Iolanda" data-original="" class="elementImage photo" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" pagespeed_url_hash="1859759222" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">
</a>
</div>
</div>
</figure>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<nav class="itemFooter">
<a class="btn btn-black icn-vetrina shinystat_ssxl" data-pag="vetrina" href="//www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda">Vetrina</a>
<a class="btn btn-blank icn-showOnMap btnShowOnMap shinystat_ssxl" data-pag="vedimappa" href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda/mappa" rel="nofollow"> <span>Vedi su mappa</span></a>
</nav>
</div>
</div>
</div>
www.paginegialle.it//ricerca//TABACCO%20PLANET?mr=50
So You might see the HTML easier.
I edited and I am adding some text because It won't let me finalize edit since it says too much code, I fixed the first part and changed from span to h1

The Xpath does not match the HTML. The relevant fragment seems to be:
<div class="hidden-phone-elem">
<div class="btn btn-yellow btn-show-phone" data-pag="mostra telefono" data-context="listing">
<span>MOSTRA TELEFONO</span>
</div>
<div class="btn btn-hidden-phone">
<span class="phIco "></span>
<span class="phone-label">081 5034556</span>
</div>
</div>
The div has only the class hidden-phone-elem and two descendant spans. Xpath 1.0 has no token selector function, but it can be emulated with string functions.
normalize-space() - replace all whitespace sequences with a single space, trim
concat() - concatenate strings
contains() - look for substring
The trick is to normalize the attribute to something like classToMatch otherClass and look if that contains classToMatch. (Take note of the spaces at the start/end).
$document = new DOMDocument();
$document->loadHTML($html);
$xpath = new DOMXpath($document);
$expression = 'string(
//div[
contains(concat(" ", normalize-space(#class), " "), " hidden-phone-elem ")
]
//span[
contains(concat(" ", normalize-space(#class), " "), " phone-label ")
]
)';
var_dump($xpath->evaluate($expression));
Output:
string(11) "081 5034556"

Related

How to pass data to another part of my html page with php?

Hi my question is: How can I pass data from my array to another part of my html code which is not in same file.
I have file item.php and index.php In index I have array with objects. Now I have to include item.php as many times as count of item in array and every time send different data to item.
Index.php
<?php
require_once('Subject.php');
$sub1 = new Subject(
'informačné technológie',
'Absolvent študijného odboru inteligentné technológie je kvalifikovaný odborný pracovník, k
torý má vedomosti a zručnosti z oblasti informačných technológií, programovania, počítačových sietí,
smart technológií, internetu vecí, databázových systémov, základov kybernetickej bezpečnosti,
robotiky, 3D technológií, serverových a cloudových technológií, grafiky, základov elektroniky,
optimalizácie riadenia procesov a problematiky súvisiacej s digitálnou firmou. Je schopný využívať
mäkké zručnosti v prezentovaní a vystupovaní.',
'slider1.png',
'video1.mp4');
$sub2 = new Subject(
'elektrotechnika',
'Absolvent študijného odboru inteligentné technológie je kvalifikovaný odborný pracovník,
ktorý má vedomosti a zručnosti z oblasti informačných technológií, programovania,
počítačových sietí, smart technológií, internetu vecí, databázových systémov, základov
kybernetickej bezpečnosti, robotiky, 3D technológií, serverových a cloudových technológií,
grafiky, základov elektroniky, optimalizácie riadenia procesov a problematiky súvisiacej s
digitálnou firmou. Je schopný využívať mäkké zručnosti v prezentovaní a vystupovaní.',
'slider2.png',
'video2.mp4'
);
... and moore subjects can be here
$subjects = array($sub1, $sub2, $sub3, $sub4, $sub5, $sub6, $sub7);
?>
<!--Header -->
<?php include("./parts/main/header.php") ?>
<main>
<div class="container-fluid p-0">
<div class="black-overlay"></div>
<div id="dod-carousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
// This I need generate for every subject
<?php include("./parts/carousel-item.php") ?>
</div>
</div>
</div>
</main>
<!--Footer -->
<?php include("./parts/main/footer.php") ?>
Item.php
<div class="carousel-item active d-flex flex-column">
<div class="carousel-bg" style="background-image:url('assets/images/slider-electro.jpg')">
</div>
<div class="carousel-content w-100 flex-grow-1 d-flex flex-column justify-content-center align-items-center">
<div class="top w-100 flex-grow-1 d-flex flex-column flex-xl-row h-100 justify-content-center align-items-center p-5">
<div class="left mr-xl-5 order-2 order-xl-1">
<h2 class="slider-caption border-red text-xl-left text-center">Informačné technológie</h2>
<div class="cst-line d-xl-none mx-auto line-orange"></div>
<p class="slider-text text-center text-xl-left my-3">
HERE COMES TEXT OF SUBJECT OBJECT
</p>
<div class="text-center text-xl-left">
<a href="HERE COMES LINK OF SUBJECT" target="_blank"
class="btn btn-orange">
<i class="fas fa-hand-point-right"></i>
Pustiť video
</a>
</div>
</div>
<div class="right order-1 order-xl-2 mb-3 mb-xl-0">
<div class="video-container position-relative">
<i class="fas fa-play-circle fa-4x position-absolute"></i>
<video>
<source src=" HERE COMES LINK OF SUBJECT" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</div>
</div>
<div class="bottom">
<?php include("navigation.php") ?>
</div>
</div>
</div>
If you have a variable in one file and then include another file from that first file, that same variable will also be available if that other file.
So in your example, if you have something like
// index.php
<?php
$subjects = [
new Subject('First Title'),
new Subject('Another Title'),
];
foreach ($subjects as $subject) {
include('item.php');
}
Then whithin your item.php you can simply access the $subject variable (exactly as it would be available within that foreach loop):
// item.php
<div class="carousel-content">
<div class="text-center">
<?php echo htmlspecialchars( $subject->getTitle() ) ?>
</div>
</div>
Of course, above is a more simplified version of your example, but it will work the same with your more detailed version.

Dynamic bootstrap tabs using php and mysql

I have Bootstrap modal tabs and it is works fine without data loop. I am trying to fill tabs using data from db(fetch), but it is not working when i am changing tabs, how can call my required tab data on press to my tab? I know that I have problem with looping or maybe "active"- class of tabs. Here is my code. What is wrong?
<div class="row">
<div class="col">
<div class="row">
<div class="col-sm-4">
<h4 class="mb-4">Ölkələr</h4>
</div>
</div>
<div class="row">
<?php
$conn = connect_to_bd();
mysqli_set_charset($conn,"utf8");
$selectolke = mysqli_query($conn, "Select t.ID as tid,t.text_az as textaz, c.textid as textid, c.olkeflag as olkeflag, c.id as cid, c.country_az as country_az from countries c, text t where t.id = c.textid");
while($selectolkerow = mysqli_fetch_array($selectolke))
{
$textid = $selectolkerow["textid"];
$country_az = $selectolkerow["country_az"];
$olkeflag = $selectolkerow["olkeflag"];
$olkeid = $selectolkerow["cid"];
?>
<div class="col-lg-4">
<div class="tabs tabs-vertical tabs-left tabs-navigation">
<ul class="nav nav-tabs col-sm-3">
<li class="nav-item active">
<a class="nav-link" href="#tabsNavigation<?php echo $textid; ?>" data-toggle="tab"><img src="lib/png/<?php echo $olkeflag; ?>.png"> <?php echo $country_az; ?></a>
</li>
</ul>
</div>
</div>
<div class="col-lg-8">
<div class="tab-pane tab-pane-navigation active" id="tabsNavigation<?php echo $textid; ?>">
<h4><?php echo header_subname_olke_select_az($olkeid); ?></h4>
<p class="notworkingcss" style="color: #fff;font-family:Verdana, sans-serifsans-serif;text-shadow: black 1px 1px 2px;font-size: 1.2em;">
<?php echo text_olke_select_az($textid, $olkeid); ?>
</p>
<div class="row portfolio-list lightbox m-0" data-plugin-options="{'delegate': 'a.lightbox-portfolio', 'type': 'image', 'gallery': {'enabled': true}}">
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/1.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/1.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/2.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/2.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="img/products/yerli/3.jpg" class="img-fluid" alt="Et mehsullari">
<span class="thumb-info-action">
<a href="img/products/yerli/3.jpg" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

Align items in 3's in PHP using HTML

Good Day All,
I am trying to align items in a row of 3. At the top of each row there is a div called "". The purpose of this div is to open a new and after every 3 items the div must be close and another one opened. I have tried the below code to my suprise it is not working. This is very weird as the MOD operand should work. Cna any of you see what I could be doing wrong?
The write picture should look like this
It is out of alignment and the blue colour fills the whole page. I do not know what I am doing wrong:
$currentRow = 1;
echo '<div class="top-box">';
while($Data=mysqli_fetch_array($Result))
{
echo '<div class="col_1_of_3 span_1_of_3">
<a href="Single.php?Query='.$Data[5].'">
<div class="inner_content clearfix">
<div class="product_image">
<img src="images/'.$Data[14].'" height="300" width="320" alt=""/>
</div>
<div class="price">
<div class="cart-left">
<p class="title">'.$Data[11].'</p>
<div class="price1">
<span class="actual">R'.$Data[13].'</span>
</div>
</div>
<div class="cart-right"> </div>
<div class="clear"></div>
</div>
</div>
</a>
</div>';
$currentRow++;
if($currentRow % 3 == 0)
{
echo '</div> ';
echo '<div class="top-box">';
}
}
When I manually repeat the items every 3 items like below, it works perfectly:
<div class="top-box">
<div class="col_1_of_3 span_1_of_3">
<a href="Single.php">
<div class="inner_content clearfix">
<div class="product_image">
<img src="images/1st_Party_Boy.jpg" height="300" width="320" alt=""/>
</div>
<div class="price">
<div class="cart-left">
<p class="title">His First Party</p>
<div class="price1">
<span class="actual">R350.00</span>
</div>
</div>
<div class="cart-right"> </div>
<div class="clear"></div>
</div>
</div>
</a>
</div>
<div class="col_1_of_3 span_1_of_3">
<a href="Single.php">
<div class="inner_content clearfix">
<div class="product_image">
<img src="images/Her_First_Party.jpg" height="300" width="320" alt=""/>
</div>
<div class="sale-box"><span class="on_sale title_shop">New</span></div>
<div class="price">
<div class="cart-left">
<p class="title">Her First of Many </p>
<div class="price1">
<span class="actual">R350.00</span>
</div>
</div>
<div class="cart-right"> </div>
<div class="clear"></div>
</div>
</div>
</a>
</div>
<div class="col_1_of_3 span_1_of_3">
<a href="Single.php">
<div class="inner_content clearfix">
<div class="product_image">
<img src="images/First_one_for_boys_and_girls.jpg" height="300" width="320" alt=""/>
</div>
<div class="price">
<div class="cart-left">
<p class="title">Their First Birthday</p>
<div class="price1">
<span class="actual">R350.00</span>
</div>
</div>
<div class="cart-right"> </div>
<div class="clear"></div>
</div>
</div>
</a>
</div>
<div class="clear"></div>
</div>
Hey change $currentRow to zero
$currentRow = 0;
echo '<div class="top-box">';
while($Data=mysqli_fetch_array($Result))
{
echo '<div class="col_1_of_3 span_1_of_3">
<a href="Single.php?Query='.$Data[5].'">
<div class="inner_content clearfix">
<div class="product_image">
<img src="images/'.$Data[14].'" height="300" width="320" alt=""/>
</div>
<div class="price">
<div class="cart-left">
<p class="title">'.$Data[11].'</p>
<div class="price1">
<span class="actual">R'.$Data[13].'</span>
</div>
</div>
<div class="cart-right"> </div>
<div class="clear"></div>
</div>
</div>
</a>
</div>';
$currentRow++;
if($currentRow % 3 == 0)
{
echo '</div> ';
echo '<div class="top-box">';
}
}

Twitter Bootstrap - How to align two <li> tags with a badge class

I've posted the image of what problem I'm facing. It's very simple:
There are two list items I want to display but they are not aligned properly. I want the End Date list item to be aligned with the green badge next to it. How do I take out the space between the grey and green badges??
The code is as follows:
<li>
<img src="/uploads/avatars/avatar.png" alt="" class="pull-left img-circle"/>
<div class="news-item-info">
<h4 class="name">{{ $name }}</h4>
<div class="position "><u>Start Date (inclusive):</u>
<div class="value pull-right badge ">
{{date('d M Y', strtotime($startdate))}}
</div>
</div>
<div class="position"><u>End Date (inclusive):</u>
<div class="value pull-right badge badge-success">
{{date('d M Y', strtotime($enddate))}}
</div>
</div>
</div>
</li>
Use bootstrap: see the following example
<div class="container">
<div class="col-lg-12">
start date
<span class="col-lg-2 pull-left">09-12-2016</span>
</div>
<div class="col-lg-12">
end date
<span class="col-lg-2 pull-left">15-12-2016</span>
</div>
</div>
Thanks to #ZimSystem's comment above. The final code I used is as follows:
<li>
<img src="/uploads/avatars/avatar.png" alt="" class="pull-left img-circle"/>
<div class="news-item-info">
<h4 class="name">{{ $name }}</h4>
<span class="key pull-left "><u>Start Date (inclusive):</u></span>
<div class="value pull-right">
<span class="badge">{{date('d M Y', strtotime($startdate))}}</span>
</div>
<span class="key pull-left"><u>End Date (inclusive):</u></span>
<div class="value pull-right">
<span class="badge badge-success">{{date('d M Y', strtotime($enddate))}}</span>
</div>
</div>
</li>

product list in category use unknown template

In an example category, the result products are listed using an unknown template. I have pagayo electronics theme as default.It uses a class called item-review and item-bottom for listing. they aren't in html code.
code is like this:
<ul class="products-grid">
<li class="item first">
<img src="http://magicfly.ir/media/catalog/product/cache/1/small_image/135x/9df78eab33525d08d6e5fb8d27136e95/1/3/13steps2.jpg" width="135" height="135" alt="13 Steps to Mentalism" />
<h2 class="product-name">13 Steps to Mentalism</h2>
<div class="ratings">
<span class="amount">1 نظر</span>
</div>
<div class="price-box">
<span class="regular-price" id="product-price-10">
<span class="price">30٬000 تومان</span> </span>
</div>
<div class="actions">
<p><button type="button" title="افزودن به سبد" class="button btn-cart" onclick="setLocationAjax('http://magicfly.ir/checkout/cart/add/uenc/aHR0cDovL21hZ2ljZmx5LmlyL21lbnRhbGlzbS5odG1s/product/10/form_key/Ql6smZ0IvKikUDgX/','10')"><span><span>افزودن به سبد</span></span></button></p>
<ul class="add-to-links">
<li>افزودن به لیست دلخواه</li>
<li><span class="separator">|</span> افزودن به مقایسه</li>
</ul>
while it should be like this (wrap with item-review and item-bottom classes):
<ul class="products-grid first odd">
<li class="item first">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/a/p/apple-tv-1.jpg" alt="Apple TV" height="210" width="210">
<div class="item-review">
</div>
<div class="item-bottom">
<h2 class="product-name">Apple TV</h2>
<div class="price-box">
<span class="regular-price" id="product-price-9">
<span class="price">$99.00</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/9/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
<li class="item">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/4/_/4.jpg" alt="Bose SoundDock Portable Digital Music System" height="210" width="210">
<div class="item-review">
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:97%"></div>
</div>
<span class="amount">2 Review(s)</span>
</div>
</div>
<div class="item-bottom">
<h2 class="product-name">Bose SoundDock Portable Digital Music System</h2>
<div class="price-box">
<span class="regular-price" id="product-price-22">
<span class="price">$399.95</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/22/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
<li class="item last">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/1/_/1.jpg" alt="Bose SoundLink Bluetooth Mobile speaker II" height="210" width="210">
<div class="item-review">
</div>
<div class="item-bottom">
<h2 class="product-name">Bose SoundLink Bluetooth Mobile speaker II</h2>
<div class="price-box">
<span class="regular-price" id="product-price-21">
<span class="price">$349.95</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/21/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
</ul>
in
/app/design/frontend/default/pagayo-theme-001/template/catalog/product/list.phtml
it is correctly wrapped but it seems it uses another theme that doesn't wrap it.
I didn't specify custom template for category or any product.
The amazing thing here is I checked list.phtml of base template and copied pagayo list.phtml to base. Just nothing happened.
I want it to use the default theme I specified in configuration Or at least find the phtml file of this piece of code to edit and make it correct.
without seeing its had to infer solution. possibilities are:
1) There can be an issue of improperly selected Magento Package.
system->configuration->Design->Package
2) If you want to see which template using on Template Path hints
system->configuration-> Developer -> Debug -> Template Path Hints select to on
clear cache and refresh the page.

Categories