I wanna get zumbai, n, and something from line of html below with simple_html_dom:
<p>
<div align="left" style="margin: 0.00mm 0.00mm ;">
<p style="font-family: Arial; font-size: 1.0em;">
<b>zumbai</b>
<i>n</i> something
</p>
</div>
here's my code :
foreach($html->find('div.align') as $tag1) {
foreach($tag1->parent()->find('p.style') as $tag2){
$words1 = $tag2->first_child();
$words11= $words1->plaintext;
$words2 = $tag2->first_child()->first_child();
$words22= $words2->plaintext;
}
}
but it doesn't works. thank you :)
Related
I'm following through the PDF version on this URL: https://www.neodynamic.com/articles/Print-PDF-from-PHP-directly-to-default-printer-without-print-dialog/
I have managed to have it running. However, I noticed that it can only print one PDF file that is saved, using the $filePath = 'files/LoremIpsum.pdf'; under the PrintPDFController.php file. Is there a way of dynamically getting contents from a database that is output on say a table as follows:
<table id="WebClientPrint">
<tr><td>ONLY PRINT THIS PART AUTOMATICALLY</td></tr>
</table>
<input type="button" onclick="How to call Table ID i.e. WebClientPrint and the default printer" value="Print" />
This means that at button click, only the contents of the table should be printed out.
Hello I once used this type of printing and it helped me, only the window for choosing a printer will pop up.
function PrintDiv() {
var contents = document.getElementById("dvContents").innerHTML;
var frame1 = document.createElement('iframe');
frame1.name = "frame1";
frame1.style.position = "absolute";
frame1.style.top = "-1000000px";
document.body.appendChild(frame1);
var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.document.open();
frameDoc.document.write('<html><head><title>DIV Contents</title>');
frameDoc.document.write('</head><body>');
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
window.frames["frame1"].focus();
window.frames["frame1"].print();
document.body.removeChild(frame1);
}, 500);
return false;
}
Use it like this
<body>
<form id="form1">
<span style="font-size: 10pt; font-weight: bold; font-family: Arial">Sample code</span>
<hr />
<div id="dvContents" style="border: 1px dotted black; padding: 5px; width: 300px">
<span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello,
<br />
This is <span style="color: #18B5F0">Mateo</span>.<br />
Hoping that you are enjoying my articles!</span>
</div>
<br />
<input type="button" onclick="PrintDiv();" value="Print" />
</form>
</body>
I hope it helps you.
I have a string like the following which can change every time.
style="margin: 0;">\r\n
Phone\r\n </p>\r\n <p style="font-weight: bold; margin:
0;">\r\n 0411313062\r\n </p>\r\n
</td>\r\n
</tr>\r\n
<tr>\r\n
<td style="padding-bottom: 18px;">\r\n
I need to extract the phone number 0411313062 out of this string.
You can try this:
$text = 'style="margin: 0;">\r\n
Phone\r\n </p>\r\n <p style="font-weight: bold; margin: 0;">\r\n 0411313062\r\n </p>\r\n
</td>\r\n
</tr>\r\n
<tr>\r\n
<td style="padding-bottom: 18px;">\r\n';
preg_match("/[0-9]{10}/", $text, $matches);// in case of multiple occurrences us preg_match_all
print_r($matches[0]);//0411313062
Try this
preg_match('\(?([0-9]{3})\s*\)?\s*-?\s*([0-9]{3})\s*-?\s*([0-9]{4})', $string, $match );
See it in action,
https://regex101.com/r/pLqDWw/3
This will match 7 or 10 digit phone numbers with or without the - or (area code) such as 800-555-5555 or 8005555555 or (800)555-5555 or 555-5555 etc
If you have to match more then one number, I would suggest using something like PHPQuery, to refine the text ( html ) you are searching for it against. You could try something simpler like, preg_match_all but once you get the hang of PHPQuery you'll thank me.
this code works fine. Try this
$tab = <<<EOD
style="margin: 0;">\r\n Phone\r\n </p>\r\n <p style="font-weight: bold; margin: 0;">\r\n 0411313062\r\n </p>\r\n </td>\r\n
</tr>\r\n
<tr>\r\n
<td style="padding-bottom: 18px;">\r\n) EOD;
$input= explode("\r\n", $tab);
print_r($input);
the phone number is
echo $input[4];
I have view file on my app there is code array I want to get first object of that array without going in loop.
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
$result is array of object I'm getting from a form. In below you can clearly see I'm chunking it to 3 more array and looping though individual objects and getting their details to html for example.
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
I want to get the first object details let's say want get $product->product_name of first object of result array without going in loop how to achieve that.
here is complete view file code.
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 0px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<div class="footer">
Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?>, $ Rate : Rs. <?php echo $usd; ?> </div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
<?php $GLOBALS['a']= $product->product_id; ?>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
ok man as i said u need to change your way of writing codes but about your specific question use this:
$result = array('a', 'b', 'c', 'd', 'e');
reset($array);
$first = current($array);
you can check this:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.current.php
But still about your way of coding. u should soon go to MVC or such ways of programming so u should separate your view and coding logics
like u may have a page like view_profile.php which is going to show user's information. in regular coding u have this:
view_profile.php:
<?php session_start();
// you check sessions to see if the user is logged in and has the right to view this page.
// like:
if ($_SESSIONS['is_user_logged_in']){
$username=$_SESSIONS['username'];
$name=$_SESSIONS['name'];
// ....
}else{
header('location: ./login.php');// if user is not authenticated u redirect to login page
exit();// prevents the rest of codes to be shown and executed
}
?>
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
But in a better way u can do it like this:
you have files like
'view_profile.htm' // holds the HTML
'view_profile.php // holds the PHP logic
'inc.php' // holds some useful functions that help you in writing PHP logic
view_profile.htm
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
inc.php
<?php
function ses_start(){
if(!session_id()){
session_start();
}
}
function ses_get($key){
ses_start();
if(!empty($_SESSION[$key])){
return $_SESSION[$key];
}
return NULL;
}
function ses_set($key,$val){
$_SESSION[$key]=$val;
}
function is_user_loggedin(){
ses_start();
if(!empty(ses_get('is_user_loggedin')){
return true;
}
return false;
}
function go($to){
header('location: '.$to);
exit();
}
//and lots of useful functions that help u connect and work with data base.
view_profile.php
<?php
include('inc.php');
if(is_user_loggedin(){
$username=ses_get('username');
$name=ses_get('name');
//...
}else{
go('login.php);
}
include('view_profile.html); // and u call the .htm file that holds the HTML the view file)
?>
this was a simple sample of separating codes logic(php codes) from views(html tags)
and also u may search about MVC Model-View-Controller and try working with simple MVC frameworks.
hello i have this code:
$thread_qry5= "SELECT * FROM xenProve_prove ORDER BY view_count DESC LIMIT 5";
$row5 = XenForo_Application::get('db')->fetchAll($thread_qry5);
foreach ( $row5 AS $rows5 ) {
$viewid = $rows5['thread_id'];
$viewtitle = $rows5['title'];
$viewuser = $rows5['username'];
$MostView .= 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>';
how can replace this symbol .= ?
Xenforo system don't read this symbol (.=)
I tried :
$MostView = 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>' . $MostView;
but don't work.
And i tried the For cycle anche the While cycle but don't work.
Thanks you
You are trying to add a string to another string (by a concatenating assignment operator) that doesn't exist (yet). You have to define the string first:
$MostView = '';
and then:
foreach ( $row5 AS $rows5 ) {
$viewid = $rows5['thread_id'];
$viewtitle = $rows5['title'];
$viewuser = $rows5['username'];
$MostView .= 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>';
I don't think this problem is related to XenForo. If you turn on error reporting (just check Google or Stack Overflow) you will get more usefull information about this error.
I've been away from programming in general for a long time. Amazing how you forget the simplest things. So I'm trying to warm-up my web design/PHP by making a resume generator.
I made my resume in Word, and I want to try to mimic the document formatting.
I tried doing this with tables, and then I scraped that because it wasn't working exactly like I wanted, and now I'm using divs and spans.
But that's breaking the formatting even more so I don't know what to do...
My main problem is getting spaces to line up precisely the way tabs do in Microsoft Word, on the same line as other things.
Here is the code I'm using
function fieldFill($fieldL, $fieldR = 'NoneAtAll'){
$numOfSpaces = 50;
echo '<div class="left">' . $fieldL . '</div>';
//if ($fieldR != 'NoneAtAll'){
// for($i = 0; $i <= $numOfSpaces - strlen($fieldL); $i++){
// echo ' ';
// //echo $i;
if ($fieldR != 'NoneAtAll'){
for($i = 0; $i <= $numOfSpaces; $i++){
echo ' ';
}
echo '<span class="rightt">' . $fieldR . '</span>';
echo '<br></br>';
}
}
And here is the CSS section
<style>
.rightt {margin: 0 0 0 300px;}
.name { font-size: 22pt;}
.sections {
padding: 15px 0px 0px 0px;
font-size: 12pt;
font-weight: bold;
text-decoration: underline;
}
.years {
font-size: 12pt;
font-weight: bold;
/*white-space:pre*/
}
.jobtits {
font-size: 12pt;
font-weight: bold;
}
</style>
I know there's already good resume generators out there but I'm doing this for the practice. Thanks
Here we go, I want to mimic this format
As of today I'm finding that this code
<div id="page-container">
<div id="leftside">
<div class="name">Name</div>
Address
<br>
City
<br>
State
<div class="sections">Objective</div>
To do good stuff!
<div class="sections">Education</div>
A college
<div class="sections">Awards</div>
Did some good stuff
<div class="sections">Job Experience</div>
<div class="jobtits">Some place</div>
Was an editor
<div class="jobtits">Another place</div>
Did stuff there too.
<div class="sections">Skills</div>
</div>
<div id="rightside">
<div class="name">That's my name</div>
Mobile: 334-223-3244
<br>
Home: 334-223-3244
<br>
Email: Email#me.com
<div class="sections">Filler</div>
Filler
<div class="sections">Filler</div>
2012-1030
<div class="sections">Filler</div>
Filler
<div class="sections">Job Experience</div>
<div class="jobtits">Jul 00 - 32</div>
Filler
<div class="jobtits">Everybody's heard</div>
About the bird.
<div class="sections">Skills</div>
</div>
</div>
is working for the most part, but there are still parts that need to overlap, such as the objective line. I probably need to make a new div/table for that huh? I'm walking through the html static before making it dynamic.
SPAN tag is inline element so margin will not be appled to it, use DIV tag instead.