php get value out of array with quotes - php

Hello! I have a few SQL statements and I need to split them, I need the first image tag that occurs in the statement, I have the code for it to split it, but the problem being all of the different quotes. Is there a way to get it out out?
Code I have now:
$array = array('INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120333,139,'Champ Cars 2007','champ-cars-2007','<table style=width: 429px; height: 74px height=74 width=429 border=0><tbody><tr><td><img title=champcar_logo_2007.jpg style=width: 200px; height: 79px height=79 alt=champcar_logo_2007.jpg hspace=5 src=images/stories/Store/champcar_logo_2007.jpg width=200 align=left vspace=5 border=0 /></td><td><div align=justify>Exclusieve toegangskaarten alleen hier te koop! Wilt u tijdens het evenement op 2 september aanwezig zijn? kijk in mijn <a class=undefined href=index.php?option=com_content&task=view&id=94&Itemid=>shop</a> en bestel snel!</div></td></tr></tbody></table><hr />','',0,8,'2007-08-10 16:21:48',367,'','2008-04-17 15:09:13',367,0,'0000-00-00 00:00:00','2007-08-10 00:00:00','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,0,'{"robots":"","author":"","rights":"","xreference":""}');,/* INSERT QUERY */INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120444,140,'Nieuwe helmen voor Nik en Koen','nieuwe-helmen-voor-nik-en-koen','<table border=0> <tbody> <tr> <td valign=top><img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 /></td> <td valign=top>Speciaal uit Amerika zijn afgelopen winter twee nieuwe IRL Bell T6 Interceptors overgevlogen. Samen met de hoofdsponsor Eurogrip en Marcel Brouwers van Tjello Creations</td> </tr> </tbody> </table>','<p>is dit design tot stand gekomen en uiteindelijk super mooi gespoten op de helmen!<br /><br /></p>',1,8,'2008-04-17 15:08:48',367,'','2012-06-20 11:37:19',367,0,'0000-00-00 00:00:00','2008-04-17 14:23:23','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,2088,'{"robots":"","author":"","rights":"","xreference":""}');');
foreach($array as $item) {
$split = preg_split('/src=/', $item);
$split = explode(' ', $split[1]);
echo $split[0] . "\n";
}
I have a few statements in a array:
INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120333,139,'Champ Cars 2007','champ-cars-2007','<table style=width: 429px; height: 74px height=74 width=429 border=0><tbody><tr><td><img title=champcar_logo_2007.jpg style=width: 200px; height: 79px height=79 alt=champcar_logo_2007.jpg hspace=5 src=images/stories/Store/champcar_logo_2007.jpg width=200 align=left vspace=5 border=0 /></td><td><div align=justify>Exclusieve toegangskaarten alleen hier te koop! Wilt u tijdens het evenement op 2 september aanwezig zijn? kijk in mijn <a class=undefined href=index.php?option=com_content&task=view&id=94&Itemid=>shop</a> en bestel snel!</div></td></tr></tbody></table><hr />','',0,8,'2007-08-10 16:21:48',367,'','2008-04-17 15:09:13',367,0,'0000-00-00 00:00:00','2007-08-10 00:00:00','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,0,'{"robots":"","author":"","rights":"","xreference":""}');,/* INSERT QUERY */
INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120444,140,'Nieuwe helme en en','nieuwe-helmn','<table border=0> <tbody> <tr> <td valign=top><img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 /></td> <td valign=top>Speciaal uit Amerika zijn afgelopen winter twee niIRL Bell T6 Interceptors overgevlogen. Samen met de hoofip en Mers van Tjeions</td> </tr> </tbody> </table>','<p>is dit design tot stand gekomen en uiteindelijk super mooi gespoten op de helmen!<br /><br /></p>',1,8,'2008-04-17 15:08:48',367,'','2012-06-20 11:37:19',367,0,'0000-00-00 00:00:00','2008-04-17 14:23:23','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,2088,'{"robots":"","author":"","rights":"","xreference":""}');
I just want
<img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 />
I am getting now is errors because of the quotes that won't resemble a correct string, anyone know a way to do this?

Parsing SQL is not trivial. (It's not hard either.) If this is a one-off job, you might get away with a few regex to pull out what you want. Otherwise you need to use a parser.
Regex /<img[^>]+>/ will extract image tags. It will fail on a variety of edge cases so don't rely on this and verify the output. And you don't need PHP for this:
egrep -o '<img[^>]+>' < old_db.sql
This is really putting the cart before the horse. Why not use the tool intended for the job: Mysql? Run the inserts, then query the data. Done. If you don't have mysql handy, try sqlite. It looks like it should be able to read your SQL.

Related

How to add a header and footer to a PDF generated with DOMPDF and Laravel 5.8

Am using barryvdh/laravel-dompdf in a Laravel 5.8 app
I have a problem with the header and footer.
Preview PDF
I have this function to Generate PDF:
public function getProductPdf(Request $request, int $id)
{
$product = $this->cmsRepository->getProduct($id);
$data = [
'title' => 'First PDF for Medium',
'heading' => 'Hello from 99Points.info',
'content' => 'Od kilku dni w szeregach Platformy Obywatelskiej trwa czas powyborczych rozliczeń. Kolejni politycy krytykują działania partii pod kierunkiem Grzegorza Schetyny, którego kadencja na stanowisku przewodniczącego kończy się za kilka miesięcy. Walki o przywództwo nie wyklucza Borys Budka. - Jestem skłonny startować w tych wyborach, bo musi być jakiś wybór - powiedział polityk w rozmowie z "Gazetą Wyborczą".'
];
$pdf = \PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif', 'defaultPaperSize' => 'a3'])->loadView('psCMS.prints.product-view', $data);
return $pdf->download('product-' . $product->id . '-' . now()->toDateString() . '.pdf');
}
This is my template to print:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{ $title }}</title>
<style type="text/css">
.page-break {
page-break-after: always;
}
/*#page {*/
/* margin: 0px 0px 0px 0px !important;*/
/* padding: 0px 0px 0px 0px !important;*/
/*}*/
th,
td,
p,
div,
b {
margin: 0;
padding: 0
}
html {
margin: 40px 50px
}
body {
font-family: DejaVu Sans;
font-style: normal;
font-weight: 400;
/*margin: 0px;*/
font-size: 18px;
}
* {
font-family: DejaVu Sans, Verdana, Arial, sans-serif;
}
a {
color: black;
text-decoration: none;
}
table {
font-size: x-small;
}
tfoot tr td {
font-weight: bold;
font-size: 18px;
}
.gray {
background-color: lightgray
}
.information {
color: black;
font-size: 18px;
}
.information .logo {
margin: 5px;
}
.information table {
padding: 10px;
font-size: 18px;
}
.document {
padding-bottom: 50px;
}
</style>
</head>
<body>
<div class="information">
<table width="100%">
<tr>
<td align="left" style="width: 40%;">
<h3>John Doe</h3>
<pre>
Street 15
123456 City
United Kingdom
<br/><br/>
Date: 2018-01-01
Identifier: #uniquehash
Status: Paid
</pre>
</td>
<td align="center">
<img src="/path/to/logo.png" alt="Logo" width="64" class="logo" />
</td>
<td align="right" style="width: 40%;">
<h3>CompanyName</h3>
<pre>
https://company.com
Street 26
123456 City
United Kingdom
</pre>
</td>
</tr>
</table>
</div>
<br />
<h1>{{ $heading}}</h1>
<div class="document">
<p>{{$content}}</p>
<table width="100%">
<tr>
<td valign="top"><img src="{{asset('images/meteor-logo.png')}}" alt="" width="150" /></td>
<td align="right">
<h3>Shinra Electric power company</h3>
<pre>
Company representative name
Company address
Tax ID
phone
fax
</pre>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td><strong>From:</strong> Linblum - Barrio teatral</td>
<td><strong>To:</strong> Linblum - Barrio Comercial</td>
</tr>
</table>
<br />
<table width="100%">
<thead style="background-color: lightgray;">
<tr>
<th>#</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Price $</th>
<th>Total $</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Playstation IV - Black</td>
<td align="right">1</td>
<td align="right">1400.00</td>
<td align="right">1400.00</td>
</tr>
<tr>
<th scope="row">1</th>
<td>Metal Gear Solid - Phantom</td>
<td align="right">1</td>
<td align="right">105.00</td>
<td align="right">105.00</td>
</tr>
<tr>
<th scope="row">1</th>
<td>Final Fantasy XV - Game</td>
<td align="right">1</td>
<td align="right">130.00</td>
<td align="right">130.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<td align="right">Subtotal $</td>
<td align="right">1635.00</td>
</tr>
<tr>
<td colspan="3"></td>
<td align="right">Tax $</td>
<td align="right">294.3</td>
</tr>
<tr>
<td colspan="3"></td>
<td align="right">Total $</td>
<td align="right" class="gray">$ 1929.3</td>
</tr>
</tfoot>
</table>
Pence poinformował po trwających ponad cztery godziny negocjacjach, że Turcja na 120 godzin zawiesi wszystkie
operacje militarne, by pozwolić kurdyjskim bojownikom na opuszczenie przygranicznego pasa w północno-wschodniej
Syrii, a gdy Kurdowie wycofają się, nastąpi rozejm.
Turcja nie będzie jednak zobligowana do wycofania swoich wojsk z Syrii. Jak pisze AP, cytując przedstawiciela
amerykańskich władz, oznacza to de facto, że Ankara otrzymała pozwolenie USA na okupowanie bezpiecznej strefy.
Negocjatorzy obu stron wydali komunikat, w którym napisano, że stworzenie bezpiecznej strefy "będzie egzekwowane
przede wszystkim przez siły zbrojne Turcji".
Wiceprezydent podkreślił też, że prezydent Donald Trump zagroził, że jeśli Ankara nie zawiesi operacji
wojskowych, to on nie wycofa obecnych sankcji nałożonych na Turcję i pozwoli na wdrożenie następnych.
Dodał, że Ankara i Waszyngton "zobowiązały się do wypracowania pokojowego rozwiązania i przyszłości dla
bezpiecznej strefy" na północnym wschodzie Syrii. Oznajmił, że amerykańskie siły w Syrii zaczęły już ułatwiać
Kurdom bezpieczne wycofanie się z przygranicznych terenów.
Pence powiedział również dziennikarzom, że Ankara obiecała, że jej wojska nie zajmą miasta Kobane (Ajn al-Arab),
nazywanego ogniskiem zapalnym tego konfliktu. Minister spraw zagranicznych Turcji Mevlut Cavusoglu oznajmił
jednak, że Ankara nie udzieliła gwarancji dotyczących Kobane, a jej armia jedynie "przerwała operacje". Dodał,
że status miasta Manbidż "i innych regionów" na północnym wschodzie Syrii, zostanie przedyskutowany z Rosją.
Kurdyjski polityk Aldar Chalil, komentując warunki rozejmu, powiedział telewizji Al-Arabija, że Erdogan chce
wedrzeć się na terytorium Syrii na głębokość 32 km, a Kurdowie już wcześniej odrzucili takie rozwiązanie. Dodał,
że aprobują zawieszenie broni, ale będą się bronić, jeśli zostaną zaatakowani.
Amerykańscy senatorowie, w tym wpływy sojusznik prezydenta Lindsey Graham, poinformowali, że niezależnie od
zapowiedzi rozejmu, będą "pełną parą" pracowali nad ustawą w sprawie nowych sankcji na Ankarę.
"Wspaniałe wiadomości z Turcji"
Trump podziękował na Twitterze Erodganowi i napisał, że otrzymał "wspaniałe wiadomości z Turcji". "Miliony
istnień ludzkich będą uratowane!" - dodał. Oznajmił, że w tej sytuacji możliwa jest wizyta Erdogana w USA w
przyszłym miesiącu.
Nazwał też prezydenta Turcji "twardym facetem", który "zrobił to, co trzeba". Dodał: "Teraz Kurdowie będą
bardziej skłonni robić to, co trzeba".
Przedstawiciel strony tureckiej po negocjacjach powiedział agencji Reutera, że Turcja "dostała dokładnie to,
czego chciała". Porozumienie pozwala Turcji uwolnić się od nałożonych już sankcji i uniknąć kolejnych, a to
oznacza, że w żaden sposób nie zostanie ukarana za inwazję w północno-wschodniej Syrii - komentuje AP.
Reuters przypomina, że ekspedycja sił tureckich zmusiła do ucieczki 200 tys. cywilów. Wzbudziła też niepokój
wspólnoty międzynarodowej o odrodzenie się Państwa Islamskiego (IS), którego bojownicy są zamknięci w
kurdyjskich więzieniach.
Turecka ofensywa wywołała też polityczną burzę w Waszyngtonie, gdzie politycy różnych afiliacji krytykowali
prezydenta za decyzję o wycofaniu amerykańskich żołnierzy z Syrii, co Ankara uznała za przyzwolenie na podjęcie
operacji wojennych - komentuje Reuters.
W środę Trump bronił swojej decyzji, nazywając ją "strategicznie błyskotliwą", ale Izba Reprezentantów tego
samego dnia przyjęła rezolucję potępiającą decyzję prezydenta o wycofaniu amerykańskich żołnierzy z Syrii.
Za rezolucją, w liczącej 435 miejsc niższej izbie Kongresu, głosowało 354 kongresmenów, czyli wszyscy Demokraci
i duża grupa Republikanów. W czwartek głosowanie nad analogiczną rezolucją zapowiedział Senat.
</div>
<footer>
<div class="footer" style="position: absolute; bottom: 0;">
<table width="100%">
<tr>
<td align="left" style="width: 50%;">
© {{ date('Y') }} {{ config('app.url') }} - All rights reserved.
</td>
<td align="right" style="width: 50%;">
Company Slogan
</td>
</tr>
</table>
</div>
</footer>
</body>
</html>
I need Header and Footer to be visible on every page in PDF.
The template looks ok, but there is a problem with the header and footer.
Header = John Doe, Company Name, etc.
Footer = Company slogan, #2019-10-17
How can I add in footer: [page number] from [number of pages]?
Add style for the header and footer page.
<style>
#page { margin: 180px 50px; }
#header { position: fixed; left: 0px; top: -180px; right: 0px; height: 150px; background-color: orange; text-align: center; }
#footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; background-color: lightblue; }
#footer .page:after { content: counter(page, upper-roman); }
</style>
Add the header part inside this div.
<div id="header">
</div>
Add Footer part in the following div.
<div id="header">
</div>
Enable DOMPDF_ENABLE_PHP from /config/dompdf.php
Publish vendor file via php artisan vendor:publish command
Pass $pdf object from controller:
List item
You should add the following script in the view file.
<script type="text/php">
if ( isset($pdf) ) {
// OLD
// $font = Font_Metrics::get_font("helvetica", "bold");
// $pdf->page_text(72, 18, "{PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(255,0,0));
// v.0.7.0 and greater
$x = 72;
$y = 18;
$text = "{PAGE_NUM} of {PAGE_COUNT}";
$font = $fontMetrics->get_font("helvetica", "bold");
$size = 6;
$color = array(255,0,0);
$word_space = 0.0; // default
$char_space = 0.0; // default
$angle = 0.0; // default
$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}
</script>

goodnight need to keep a calendar event laravel

goodnight need to keep a calendar event laravel and make a calendar but I can not do any other please Amano in this and in advance thank you very much
this is the code of my calendar
<?php
$month=date("n");
$year=date("Y");
$diaActual=date("j");
$diaSemana=date("w",mktime(0,0,0,$month,1,$year))+7;
$ultimoDiaMes=date("d",(mktime(0,0,0,$month+1,1,$year)-1));
$meses=array(1=>"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio",
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
?>
<!DOCTYPE html>
<html lang="es">
<head>
<title>calendario </title>
<meta charset="utf-8">
<style>
#calendar {
font-family:Arial;
font-size:12px;
}
#calendar caption {
text-align:left;
padding:5px 10px;
background-color:#003366;
color:#fff;
font-weight:bold;
}
#calendar th {
background-color:#006699;
color:#fff;
width:40px;
}
#calendar td {
text-align:right;
padding:2px 5px;
background-color:silver;
}
#calendar .hoy {
background-color:red;
}
</style>
</head>
<body>
<h1>calendario </h1>
<table id="calendar">
<caption><?php echo $meses[$month]." ".$year?></caption>
<tr>
<th>Lun</th><th>Mar</th><th>Mie</th><th>Jue</th>
<th>Vie</th><th>Sab</th><th>Dom</th>
</tr>
<tr bgcolor="silver">
<?php
$last_cell=$diaSemana+$ultimoDiaMes;
// hacemos un bucle hasta 42, que es el máximo de valores que puede
// haber... 6 columnas de 7 dias
for($i=1;$i<=42;$i++)
{
if($i==$diaSemana)
{
// determinamos en que dia empieza
$day=1;
}
if($i<$diaSemana || $i>=$last_cell)
{
// celca vacia
echo "<td> </td>";
}else{
// mostramos el dia
if($day==$diaActual)
echo "<td class='hoy'>$day</td>";
else
echo "<td>$day</td>";
$day++;
}
// cuando llega al final de la semana, iniciamos una columna nueva
if($i%7==0)
{
echo "</tr><tr>\n";
}
}
?>
</tr>
</table>
</body>
</html>
this is the structure I only need to add the event and select dates mvc but everything goes to get here

How to change VAR?

I've got a part of a PHP script, but it gives a T_CLASS error.
But i'm not sure how to convert the VAR element into a php5 compliant code...
Can somebody help me?
<?php // Defining the "calc" class
if (!class_exists('calc'))
class calc {
var $number1;
}
?>
p.s. this is just part of a bigger code, but it keeps saying: "PHP Syntax Check: Parse error: syntax error, unexpected T_CLASS in your code on line 3". So the error should be either in "class calc {" or in "var $number1;". Please help :P
I had to place the entire code. Just adding the brackets gave me a new error.
<?php // Defining the "calc" class
if (class_exists('calc')) {
class calc {
var $number1;
}
}
function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
//Creating object of class
$calc = new calc();
?>
<style type="text/css">
.calcbutton {
Cursor: pointer;
display: block;
text-indent: -5000px;
width: 136px;
height: 44px;
border: none;
background-image: url('http://www.mijncreaties.com/wp-content/themes/GoedVerwoord/images/buttons.png');
background-repeat: no-repeat;
}
.calcbutton {background-position: top left;}
.calcbutton:hover {background-position: center left;}
.calcbutton:active {background-position: bottom left;}
</style>
<form name="calc" action="" method="POST">
<table>
<tr>
<td>Aantal pagina's: </td>
<td><input type="text" style="padding-left: 3px;" class="calc-form wpcf7-text" name="value1" value="0" onfocus="if (this.value == '0') {this.value = '';}" onblur="if (this.value == '') {this.value = '0';}"><br>
<input type="hidden" name="oper" value="boek">
</td>
</tr>
</table>
<input type="submit" value="Bereken prijs" name="submit" class="calcbutton">
</form>
<?
if($_POST['submit']){
$number1 = $_POST['value1'];
$oper = $_POST['oper'];
if(!$number1){
echo "<p><font color=\"red\">Vul a.u.b. een getal in.</font></p>";
}
if($oper == "boek"){
$calc->boek($number1);
}
}
?>
Try wrapping it in an extra set of braces:
<?php // Defining the "calc" class
if (!class_exists('calc')) {
class calc {
var $number1;
}
}
?>
Editted to add:
if (class_exists('calc')) {
class calc {
var $number1;
function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
}
Your closing bracket was in the wrong place.
Wrap brackets around that if:
<?php
// Defining the "calc" class
if (!class_exists('calc')){
class calc {
var $number1;
}
}
?>
You will have the same issue when conditionally creating functions:
<?php
if (!function_exists('new_function')){
function new_function{
return 'awesome';
}
}
?>

IE8 Php header location opens a new window

I have a page dynamically filled with content from PHP and databases, the content is loaded into an iframe. Now when I make a custom search, the results are coming out fine on all browsers BUT IE8 (and maybe earlier versions). The browser sorts the results in a new window instead of filling the iframe!
my php search page:
<?php
if (isset($_REQUEST[searchname])) {
$searchname = $_REQUEST[searchname];
if (strlen($searchname) < 3) {
$location = "necrologies_iframe.php?action=tooshort";
header("Location: {$location}");
} else {
$location = "necrologies_iframe.php?action=search&nom={$searchname}";
header("Location: {$location}");
}
}
?>
Is there a way to fill the iframe with results instead of opening a new window?
Edit
The search form/button:
<form id="form1" name="form1" method="get" target="frame" action="http://www.cablevision.qc.ca/fr/code/necrologies_search.php">
<p><strong><a href="javascript:void(0);" onClick="necro_search('est');" >Abitibi-Est</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=est-->
<a href="javascript:void(0);" onClick="necro_search('ouest');" >Abitibi-Ouest</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=ouest"-->
<a href="javascript:void(0);" onClick="necro_search('rn');" >Rouyn-Noranda</a> | <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=rn"-->
Témiscamingue <!--//href="index.php?option=com_content&view=article&id=123&Itemid=146&action=temis"-->
</strong> |
<input name="searchname" type="text" id="searchname" value=<?php if (isset($_REQUEST[nom])) { echo '"' . $_REQUEST[nom] . '"'; } else { echo '"rechercher les archives"'; } ?> size="25" />
<input type="submit" name="submit" id="submit" value="Rechercher" />
The iframe part of the page
<iframe id="frame" "width="638px" frameborder="0" src="code/necrologies_iframe.php" scrolling="yes" horizontalscrolling="no" verticalscrolling="yes"></iframe>
the iframe page code
<style type="text/css">
<!--
table
{
line-height: 135%;
font-family: Arial, Helvetica, sans-serif;
font-size:13px;
}
.border {
border: 1px solid #000000;
}
.borderbas {
border-bottom: 1px solid #000000;
}
.padding {
padding: 5px;
}
-->
</style>
<?php
// fichier de connection a la DB
require_once("includes/connection.php");
require_once("includes/functions.php");
?>
<?php
$action = $_REQUEST[action];
$datedujour = date("Y-m-d");
switch ($action) {
case "search":
$searchname = utf8_decode(mysql_prep($_REQUEST[nom]));
$necroresult = mysql_query("SELECT * FROM necrologies WHERE nom LIKE '%{$searchname}%' AND approuve = '1' ORDER BY id DESC ");
if (mysql_affected_rows() == 0) {
// message que je fais afficher si il ne trouve rien (au lieu d'une page blanche qui ne veux rien dire
$message = "<br /><br /><br /><br /><h3>Aucun résultat trouvé </h3><br>Veuillez modifier le nom de la recherche...<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
} else {
// sinon on affiche le nombre de resultats trouvés
$necro_num_rows = mysql_num_rows($necroresult);
$message = $necro_num_rows . " résultat(s) trouvés...";
$affiche_liste = 1;
}
break;
case "tooshort":
echo "<br><br><center>Recherche trop courte, veuillez entrer plus de 4 caractères...</center><br><br><br><br><br><br><br><br><br><br><br><br><br>";
break;
case "est":
case "ouest":
case "rn":
case "temis":
$affiche_liste = 1; // pour faire afficher la liste des necro
$necroresult = mysql_query("SELECT * FROM necrologies WHERE datefin > '{$datedujour}' AND approuve = '1' AND region = '{$action}' ORDER BY id DESC ");
break;
default:
// default on vois toutes les necro de toute les regions
$necroresult = mysql_query("SELECT * FROM
necrologies WHERE datefin > '{$datedujour}' AND approuve = '1'
ORDER BY id DESC ");
$affiche_liste = 1;
}
?>
<br />
<?php
// affichage du message
if (isset($message)) {
echo "<br><strong><center>" . $message . "</strong></center><br>";
}
// liste des necro dans des tables
if ($affiche_liste == 1 || !isset($_REQUEST[action])) {
while ($row = mysql_fetch_array($necroresult)) {
?>
<!-- Debut de la table fancy round corner -->
<div align="center">
<table border="0" align="left" cellpadding="0" cellspacing="0" class="tb">
<tr>
<td width="16"><img src="/fr/images/roundtable/top_lef.gif" width="16" height="16"></td>
<td height="16" background="/fr/images/roundtable/top_mid.gif"><img src="/fr/images/roundtable/top_mid.gif" width="16" height="16"></td>
<td width="24"><img src="/fr/images/roundtable/top_rig.gif" width="24" height="16"></td>
</tr>
<tr>
<td width="16" background="/fr/images/roundtable/cen_lef.gif"><img src="/fr/images/roundtable/cen_lef.gif" width="16" height="11"></td>
<td align="center" valign="middle" bgcolor="#FFFFFF">
<!-- Debut du content de la table fancy round corner -->
<table width="576" border="0" cellspacing="0" cellpadding="0" class="border" >
<tr >
<td rowspan="2" valign="top"><img src="/fr/images/necrologies/<?php echo utf8_encode($row['photo']); ?>" alt="photo" /><br><img src="/fr/images/cnq/imprimable.gif" border="0" width="150" height="50"></td>
<td width="200" bgcolor="#DFEFFF" class="borderbas" style="border-left: 1px solid #000000; border-right: 1px solid #000000"><center><?php echo nl2br(mb_convert_encoding($row['nom'], "UTF-8", "Windows-1252")); ?></center></td>
<td bgcolor="#DFEFFF" class="borderbas">
<center>
<strong>
<?php
$maison = $row[maison];
if ($maison == "N/D") {
echo "(information non disponible)";
} else {
if (substr($maison, 0, 6) == "La dir") {
echo utf8_encode($maison);
} else {
echo "La direction des funérailles a été confiée à/aux <br>";
echo utf8_encode($maison);
}
}
?>
</strong></center></td>
</tr>
<tr>
<td style="border-left: 1px solid #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;" colspan="2"><div class="padding" align="left"><?php echo nl2br(mb_convert_encoding($row['description'], "UTF-8", "Windows-1252")); ?></div></td>
</tr>
</table>
<!-- Fin du content de la table fancy round corner -->
</td>
<td width="24" background="/fr/images/roundtable/cen_rig.gif"><img src="/fr/images/roundtable/cen_rig.gif" width="24" height="11"></td>
</tr>
<tr>
<td width="16" height="16"><img src="/fr/images/roundtable/bot_lef.gif" width="16" height="16"></td>
<td height="16" background="/fr/images/roundtable/bot_mid.gif"><img src="/fr/images/roundtable/bot_mid.gif" width="16" height="16"></td>
<td width="24" height="16"><img src="/fr/images/roundtable/bot_rig.gif" width="24" height="16"></td>
</tr>
</table>
</div>
<!-- Fin de la table fancy round corner -->
<!--[if IE 8]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<!--[if IE 7]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<!--[if IE 6]>
<style type="text/css">
.tb{
float:left;
align:left;
width:550px;
scrolling-horizontal:none;
}
</style>
<![endif]-->
<br /><br />
<?php
}
}
?>
<?php
// close la connection
mysql_close($connection);
?>
Targets should be named frames or windows; older browsers do not use a frame's ID. So change:
<iframe id="frame" ...
To
<iframe name="frame" id="frame" ...

Get the first 200 characters of a string without breaking HTML tags at the end

EDIT: The key point is about getting the first 200 characters and closing all tags, that are left open.
I'm currently loading articles from other website via DOM object (the other website have no RSS). I want to make a "preview" of that article, but here are my problems:
I do not control how the articles are written, therefore it seems to always be inside a table on the second TR (they use a CMS and it is messy - see example below).
They have A LOT of HTML tags, I don't want to leave one open.
I need to keep the HTML format, I know it's ugly but it fits perfectly in my page.
Not my code (in French sorry):
<table>
<TR >
<TD class='Normal' valign="top" colspan="2" style="padding-bottom:15px;">13-01-2012 <b>Water-polo – Championnat pan-pacifique<b ></TD>
</TR><TR >
<TD class='Normal' valign="top"><span class="HeadTitleNews"> Les Canadiennes disputeront le bronze aux Chinoises</span> <img src='http://www.sportcom.qc.ca/Portals/0/2011WaterpoloF.jpg' width='165' align='right' class='imgAnnouncementCss'><div style="margin: 0in 0in 0pt"><span style="font-family: Tahoma; font-size: 10pt">Montréal, 13 janvier 2012 (Sportcom) – L’équipe féminine canadienne de water-polo a remporté une victoire écrasante de 19-3 face au Brésil, vendredi, au Championnat pan-pacifique de Melbourne, en Australie. Les Canadiennes se sont ainsi assurées de participer au match pour la médaille de bronze contre les Chinoises. </span></div>
<div style="margin: 0in 0in 0pt"> </div>
<div style="margin: 0in 0in 0pt"><span style="font-family: Tahoma; font-size: 10pt">La Montréalaise <strong>Sophie</strong></span><strong><span style="font-family: Tahoma; font-size: 10pt"> Baron-La Salle</span></strong><span style="font-family: Tahoma; font-size: 10pt"> a marqué quatre buts dans la victoire. </span></div>
<div style="margin: 0in 0in 0pt"> </div>
Thanks.
<?php
$your_string_without_tags = strip_tags($your_string);
$your_200_char_string = substr($your_string_without_tags, 0, 200);
?>
Close open HTML tags in a string
You can use strip_tags function to remove all the html tags and then use it as you wish.

Categories