PHP Cut text between substrings with regexp - php

I need to extract from this html:
<div class="list-group">
<a class="list-group-item active">
<h4 class="list-group-item-heading">{EVENT_GROUP_TIME}</h4>
</a>
{EVENTS:}
<a class="list-group-item">
<h4 class="list-group-item-heading">{EVENT_NAME}</h4>
<p class="list-group-item-text"><i>{EVENT_LECTURER}</i></p>
<p class="list-group-item-text">{EVENT_TIME}</p>
<p class="list-group-item-text">{EVENT_LOCATION}</p>
</a>
{ENDEVENTS}
</div>
Two substring: with {EVENTS:}...{ENDEVENTS} block and second is everything else. In other words:
$group_header =
<div class="list-group">
<a class="list-group-item active">
<h4 class="list-group-item-heading">{EVENT_GROUP_TIME}</h4>
</a>
</div>
and $group_body =
<a class="list-group-item">
<h4 class="list-group-item-heading">{EVENT_NAME}</h4>
<p class="list-group-item-text"><i>{EVENT_LECTURER}</i></p>
<p class="list-group-item-text">{EVENT_TIME}</p>
<p class="list-group-item-text">{EVENT_LOCATION}</p>
</a>
I tried to make it with substr but it seems to be too slow with big date. Can someone suggest how to make such operation with regexp in php?

The Regular Expression You Need is this:
/(.*)({EVENTS:}(.*){ENDEVENTS})(.*)/s
Here is the complete PHP Code to test it:
<?php
$regex = "/(.*)({EVENTS:}(.*){ENDEVENTS})(.*)/s";
$string = "
<div class=\"list-group\">
<a class=\"list-group-item active\">
<h4 class=\"list-group-item-heading\">{EVENT_GROUP_TIME}</h4>
</a>
{EVENTS:}
<a class=\"list-group-item\">
<h4 class=\"list-group-item-heading\">{EVENT_NAME}</h4>
<p class=\"list-group-item-text\"><i>{EVENT_LECTURER}</i></p>
<p class=\"list-group-item-text\">{EVENT_TIME}</p>
<p class=\"list-group-item-text\">{EVENT_LOCATION}</p>
</a>
{ENDEVENTS}
</div>
";
preg_match($regex,$string,$matches);
print_r($matches);
?>
Reference for the "s" modifier:
http://php.net/manual/en/reference.pcre.pattern.modifiers.php

Related

How to create anchor tag one page to another page and open a specific div whrer i want to show data in codeigniter

this is second page
<div class="accordion__item">
<a href="<?= base_url(); ?>client/progress?id#$habit->id; ?> ">
<div class="accordion__header collapsed" data-toggle="collapse" data-target="#bordered_no-gutter_collapseThree">
<span class="accordion__header--text">Progress By Habit</span>
<span class="accordion__header--indicator style_two"></span>
</div>
</a>
<div id="bordered_no-gutter_collapseThree" class="collapse accordion__body" data-parent="#accordion-four">
<?php
if (!empty($all_habits)) {
foreach ($all_habits as $habit) { ?>
<div class="accordion__header accordion" id="prog_habit" value="<?= $habit->id; ?>">
<span class="accordion__header--text"></span><?= $habit->title; ?></span>
</div>
<?php }
} ?>
</div>
</div>
this is first page where i want to redirect this page:
<i class="fa fa-eye"></i>
You need to use fragments in first page url Like this :
<i class="fa fa-eye"></i>
And Second Page Like this
<div class="accordion__item" id="mydiv">
<a href="<?= base_url(); ?>client/progress?id#$habit->id; ?> ">
<div class="accordion__header collapsed" data-toggle="collapse" data-target="#bordered_no-gutter_collapseThree">
<span class="accordion__header--text">Progress By Habit</span>
<span class="accordion__header--indicator style_two"></span>
</div>
</a>
<div id="bordered_no-gutter_collapseThree" class="collapse accordion__body" data-parent="#accordion-four">
<?php
if (!empty($all_habits)) {
foreach ($all_habits as $habit) { ?>
<div class="accordion__header accordion" id="prog_habit" value="<?= $habit->id; ?>">
<span class="accordion__header--text"></span><?= $habit->title; ?></span>
</div>
<?php }
} ?>
</div>
I hope this code working for you!
Happy Coding!

dynamic tab using php

Hi everyone I'm niubbie in php.I have a problem with tab. I would like the tabs on their click to show a different topic. All this using php and calling the db.
My DB:
giorno
pranzo
cena
lunedi
12:00
20:00
martedi
12:00
20:00
mercoledi
12:00
20:00
giovedi
12:00
20:00
venerdi
12:00
20:00
Days are represented by tabs and when I click on a different day I want it to show lunch and dinner of that particular day.
My code:
<section class="big-section bg-light-gray border-top border-color-medium-gray wow animate__fadeIn">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12 text-center margin-six-bottom">
<h6 class="alt-font text-extra-dark-gray font-weight-500">Orari</h6>
</div>
</div>
<div class="row justify-content-center">
<div class="col-12 col-lg-10 tab-style-05">
<div class="tab-box">
<!-- start tab navigation -->
<ul class="nav nav-tabs margin-7-rem-bottom md-margin-5-rem-bottom xs-margin-15px-lr align-items-center justify-content-center font-weight-500 text-uppercase">
<?php
$sql = "SELECT * FROM orari_ristorante ";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
$i=0;
while ($riga = mysql_fetch_assoc($risultato)){
?>
<?php if($i == 0){?>
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }else{?>
<li class="nav-item alt-font"><a class="nav-link" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }
$i++;
}?>
</ul>
<!-- end tab navigation -->
</div>
<div class="tab-content">
<!-- start tab content -->
<div class="tab-pane med-text fade in active show" id="tab-nine1">
<div class="panel-group accordion-event accordion-style-04" id="accordion1" data-active-icon="icon-feather-minus" data-inactive-icon="icon-feather-plus">
<!-- start accordion item -->
<div class="panel border-color-black-transparent">
<div class="panel-heading">
<?php
$sql = "SELECT pranzo,cena FROM orari_ristorante LIMIT 1";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
while ($riga = mysql_fetch_assoc($risultato)){
?>
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<?php
}
?>
</div>
</div>
</div>
</div>
<!-- end tab content -->
</div>
</div>
</div>
</div>
</section>
My problem is that each tab shows all the rows and not the specific one for that day
My Problem
You need to ensure you are using unique ID's for your contents and using them in your href of the tab.
Reading your code it looks like each tab is created with the same ID
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
I would echo out the unique id from the database eg.
href="#tab-<?echo $riga['id'];?>" (or whatever your unique column header is)
Ensure you also echo this out further down when the tab content is being created.
Based on what you are trying to accomplish, if you limit your results to one, you will always only show the first day in the db. Here's how I would change your second while loop.
<?php
$sql = "SELECT * FROM orari_ristorante";
$risultato = mysqli_query($conn, $sql);
$i = 0;
while ($riga = mysqli_fetch_assoc($risultato)){
if($i == 0){
$css = ""
}else{
$css = "display:none"
}
?>
<div class="giorno_tab <?php echo $riga['giorno'] ;?>" style="<?php echo $css ;?>">;
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
</div>
<?php
$i++;}
?>
</div>
It is not the solution, however you can build on top of that to accomplish what you are trying to do. Hopefully that somewhat helps.
Just to explain, I was adding $riga["giorno"] as an kind of ID in the class, however Revbo's answer would give a clearer code when it comes to an ID

How to get page number dynamically when genration custom TOC in mpdf?

I am trying to create custom TOC in mpdf on first page but not sure how to get the page number for dynamic content. Can anyone please help?
$html = '<div class="frame frame-top">
<div class="mpdf_toc" id="mpdf_toc_0">
<div class="mpdf_toc_level_0">
<a class="mpdf_toc_a" href="#__mpdfinternallink_1">
<span class="mpdf_toc_t_level_0">Section 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_1">
<span class="mpdf_toc_p_level_0">5</span>
</a>
</div>
<div class="mpdf_toc_level_1">
<a class="mpdf_toc_a" href="#__mpdfinternallink_2">
<span class="mpdf_toc_t_level_1">Chapter 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_2">
<span class="mpdf_toc_p_level_1">5</span>
</a>
</div>
<div class="mpdf_toc_level_2">
<a class="mpdf_toc_a" href="#__mpdfinternallink_3">
<span class="mpdf_toc_t_level_2">Topic 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_3">
<span class="mpdf_toc_p_level_2">5</span>
</a>
</div>
</div>
You cannot, pages are determined during putting the document together when the Output() method is called and the content is finalized.

Cannot get get right value with XPath

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"

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>

Categories