PHP/CSS - detect nl2br breaks - php

I have an array of various input boxes, that when filled, fills up the database with information. Then, from another file, I take the information and print it out to the screen.
What I want to do is to put a symbol in front of each line, however using something like .style br {}; doesn't seem to work.
Reading the from MySQL, using Wordpress if that matters.
EDIT:
I was asked to post how I want it to look like. I think this is pretty straight-forward, but here it is anyway:
# Entry1
# Entry2
# Entry3
EDIT #2:
I would prefer it to be in CSS, if that's not possible, then PHP. Javascript would be the last solution that I want.
I have tried the following and it didn't work at all:
.myform.lines br {
border-bottom: 1px dashed #000000;
background-color: #ffffff;
display: block;
}

Hi have a look at Can you target <br /> with css?
I tried the following html page:
<html><head><title>Test</title>
</head><body>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('br').replaceWith('<br># ');
});
</script>
hi<br>
there<br>
testing<p>
again<p>
</body></html>
This results in
hi
# there
# testing
again
Here is some more code that also does basically the same thing - it adds a symbol (#) at the start of each line (assuming new lines follow a br).
<html><head><title>test2</title>
<script type="text/javascript">
function replaceLineBreaksWithHorizontalRulesInElement(element)
{
elems = element.getElementsByTagName( 'br' );
for ( var i = 0; i < elems.length; i ++ )
{
br = elems.item( i );
txt = document.createTextNode("# ");
br.parentNode.insertBefore(txt, br.nextSibling);
}
}
</script>
</head>
<body onload="replaceLineBreaksWithHorizontalRulesInElement(document)">
testing<br>
one<br>
two<br>
three<br>
four<br>
five<p>
six<p>
</body></html>
Note that this does work in both firefox and internet explorer giving the same results. If you remove the space however then firefox shows a space anyway, and internet explorer shows no space. I think this won't be an issue for you though, since you want the space.

How about
.mySelector:before { content: '#'; }

Related

Laravel wkhtmltopdf - text in the bottom of the last page

I'm generating an invoice PDF using laravel snappy wkhtmltopdf
and I'm tring to add some text in the bottom of the last page,
now i already have a footer-html with the number of the page.
I tried to show the content only in the last page with this way:
<!DOCTYPE html>
<div id="footer_text">
{!! nl2br($footer_text) !!}
</div>
<div class="pagination"><span id='page'></span> of <span id='topage'></span></div>
<script>
function remove(id) {
var elem = document.getElementById(id);
return elem.parentNode.removeChild(elem);
}
var vars={};
var x=window.location.search.substring(1).split('&');
for (var i in x) {
var z=x[i].split('=',2);
vars[z[0]] = unescape(z[1]);
}
document.getElementById('page').innerHTML = vars.page;
document.getElementById('topage').innerHTML = vars.topage;
if( vars.page != vars.topage && vars.topage > 1){
document.getElementById('footer_text').innerHTML = '';
remove('footer_text');
}
if(vars.topage == 1){
document.getElementById('pages').innerHTML = '';
}
</script>
and it does show me the text only in the last page BUT in the previous pages I have a big white space, here is a screenshot:
page number 1:
page number 2:
I feel like i tried everything, please help me
There is no issue with your script it might be some style issue. As you are removing footer_text in all previous pages and showing only on last page and this is somehow creating too much space. Check your CSS there must be margin-bottom or padding-bottom which is creating too much space. Enjoy!
Late to the party but looks like the ID footer_text will be set multiple times and ID's should be unique so I guess it would have worked if you used a class instead and getElementsByClassName
The footer height can't be dynamic on a different page when using Wkhtmltopdf. It's always with a static height. If this is your footer.html you have to add to your style:
body {height: 70px /for example/; position: relative;}
so you can align bottom (with position:absolute; bottom:0;) you #footer_text and content. But still, have some white space on all prev pages.
In the PDF generators, the footer content area is independent of the body content.

Print HTML table to dot matrix printer

I have a php website which generate invoice in the form of html tables, I need to print these html tables to dot-matrix printer. I have tried to print webpage directly with browser print option, but it seems the printer treat it as image because it prints characters dot-by-dot instead of complete characters in a single pass like it would an ascii text file, which result in blurred characters.
Is there any way to make the printer treat it as text file? Or is there any way to convert html page to text file without losing the position styling(spacing, margins, etc)?
Or maybe there's an alternative approach I could use?
One thing to note is I can't use text-based browser to do this as it will be used by clients.
The invoice is a html table with small logo at the top-left, title, and description as thead, and simple table cell with borders as tbody.
I use Epson LX300+II printer.
<?php
// Download printer driver for dot matrix printer ex. 1979 Dot Matrix Regular or Consola
?>
<html>
<head>
<title>PHP to Dot Matrix Printer</title>
<style>
#font-face { font-family: kitfont; src: url('1979 Dot Matrix Regular.TTF'); }
.customFont { /* <div class="customFont" /> */
font-style: kitfont;
font-size:10;
}
#mainDiv {
height: 324px; /* height of receipt 4.5 inches*/
width: 618px; /* weight of receipt 8.6 inches*/
position:relative; /* positioned relative to its normal position */
}
#cqm { /* <img id="cqm" /> */
top: 10px; /* top is distance from top (x axis)*/
left: 105px; /* left is distance from left (y axis)*/
position:absolute; /* position absolute based on "top" and "left" parameters x and y */
}
#or_mto {
position: absolute;
left: 0px;
top: 0px;
z-index: -1; /*image */
}
#arpno {
top: 80px;
left: 10px;
position:absolute;
}
#payee {
top: 80px;
left: 200px;
position:absolute;
}
#credit {
top: 80px;
right: 30px; /* distance from right */
position:absolute;
}
#paydate {
top: 57px;
right: 120px;
position:absolute;
}
</style>
</head>
<body>
<?php
//sample data
$arpno = 1234567;
$payee = "Juan dela Cruz";
$credit = 10000;
$paydate = "Dec. 6, 2015" ;
?>
<div id="mainDiv"> <!-- invisible space -->
<div id="cqm" class="customFont">ABC TRADING</div>
<div id="arpno" class="customFont"><?php echo $arpno; ?></div>
<div id="payee" class="customFont"><?php echo $payee; ?></div>
<div id="credit" class="customFont"><?php echo $credit; ?></div>
<div id="paydate" class="customFont"><?php echo $paydate; ?></div>
<img id="or_mto" src="or_mto.jpg" /> <!---- sample for logo ---->
</div>
</body>
</html>
For anyone looking to print directly from browser to printer, and assuming you need to print text only, I found the answer in this post how-to-print-page-in-plain-text-format-for-matrix-dot-printer
Github for the application is here.
A simple tutorial can be found here.
Basically you install QZ Tray in your client machine and you add the script provided by them in your html.
Works OK in Windows 10 with a OKI 320 Turbo Dot Matrix Printer, but you have to change the driver for the printer to Generic / Text Only.
Then in javascript you just do something like this:
try {
await qz.websocket.connect();
console.log("connected")
const printer = await qz.printers.find("OKI");
console.log(`Printer ${printer} found !`);
const config = qz.configs.create(printer);
const data = [
'Some Data \n',
'More Data and More Data \n'
]
qz.print(config, data);
} catch(e) { console.log(e) }
Works like a charm!
We used to do this using a Java Applet that could write to the LPT port after due permissions on the browser and Java security.
However support for this has been phased out by all browsers. We are running it right now by using older versions of the browsers.
One way we are exploring is the possibility of a java service running on a port on the local PC and calling this service from the browser window.
an option to solve this problem is to download the TCPDF library https://tcpdf.org/docs/srcdoc/ and pass the reports to pdf but you have to download some dotmatrix type font and using the link http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf, convert fonts to the format that TCPDF uses.
I had almost same requirement like this, i didn't get a perfect solution, so I used an alternative solution,
converted the html to text with the help of "w3m"
send this text to a python script running on a client machine through socket communication
through the python script(used pyusb) i sent this text directly to the printer via USB and printed.
In this solution, can't get all the solution in print.

Regex/PHP: How to remove linebreaks from within a special pattern

i got another problem removing linebreaks from within a token in a template file - the template i have to parse could look something like this:
<html>
<style>
body { color: black }
div {
background-color:#fff;
}
<!-- i need to remove the line breaks within {_WP_token[*]} for parsing //-->
<h4>{_WP_token[id="42";class="foo"; style="border:4px solid
green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
<script>
function() {
console.log('my foo is my castle');
}
</script>
I tried myself without making the break-through. i just succeeded in creating a greedy one, which eats up the first half of the token - here it is:
preg_replace("/(\{_(.*?)(.*\s))/ix", "[LB REMOVED]", $htmlTemplate);
returns
<html>
<style>
body { color: black }
div {
background-color:#fff;
}
<!-- it just ate up the first half of my token ! //-->
<h4>[LB_REMOVED]green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
<script>
function() {
console.log('my foo is my castle');
}
</script>
i made a fiddle here: http://www.phpliveregex.com/p/2EZ
thank you very much in advance.
best regards,
Lupo
Try:
$newString = preg_replace("/[\n\r]/","[LB_REMOVED]", $originalString);
I am not sure I understand you correctly. If you want to change
<h4>{_WP_token[id="42";class="foo"; style="border:4px solid
green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
into
<h4>{_WP_token[id="42";class="foo"; style="border:4px solid green;padding:20px"; onclick="(this.value=confirm('foo'));"]}</h4>
Then you can use this
\{_(.*)[\r\n]+
and replace with $1, See it on Regexr
preg_replace("/\{_(.*)[\r\n]+/", "$1", $htmlTemplate);
I removed all your modifiers, since you do not use them. See Modifiers doc

Echoing out JavaScript with nested quotes from a PHP script onto an HTML page?

I've been trying for about two hours to get the following code stored in a PHP string and then echoed out as JavaScript on a webpage:
<div id="reply-box" style="display: block; width:100%;float:right;">
<script type="text/javascript" src="http://example.com/public/js/3rd_party/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
/* Dynamic items */
CKEDITOR.config.IPS_BBCODE = {"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"ads1":{"id":"46","title":"ads1","desc":"","tag":"ads1","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"background":{"id":"27","title":"Background-color","desc":"Adds a background color behind the text","tag":"background","useoption":"1","example":"[background=red]Red background behind this text[/background]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"Entry ID","menu_content_text":"Text to display","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"Blog ID","menu_content_text":"Text to display","single_tag":"0","optional_option":"0","image":""},"code":{"id":"13","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"0","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"Code","single_tag":"0","optional_option":"0","image":""},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"Blog entry extract","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]<div class='outer'>\n <p>Hello World</p>\n </div>[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"HTML Code","single_tag":"0","optional_option":"0","image":""},"imgr":{"id":"39","title":"Image","desc":"Displays linked images, floating to the right","tag":"imgr","useoption":"0","example":"[imgr]http://www.google.com/intl/en_ALL/images/logo.gif[/imgr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"jump":{"id":"45","title":"jump","desc":"","tag":"jump","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"media":{"id":"32","title":"Media","desc":"Allows a user to post media content from certain common media sites","tag":"media","useoption":"1","example":"[media]http://www.youtube.com/watch?v=YqqLx-2vUr0[/media]","switch_option":"0","menu_option_text":"Dimensions (Flash Only)","menu_content_text":"Media URL","single_tag":"0","optional_option":"1","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=admin] runs this site.","switch_option":"0","menu_option_text":"Member Name","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"page":{"id":"38","title":"Multi-Page Articles","desc":"This tag can be used to create multi-page articles. Page links are automatically added based on the number of times this tag is used, and the content is hidden until you reach the specified \"page\".","tag":"page","useoption":"0","example":"Content 1\n[page]\nContent 2\n[page]\nContent 3","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"overline":{"id":"42","title":"Overlined Text","desc":"Makes the text overlined","tag":"overline","useoption":"0","example":"[overline]This text is underlined[/overline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"PHP Code","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"pre":{"id":"43","title":"pre","desc":"","tag":"pre","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"SQL Commands","single_tag":"0","optional_option":"0","image":""},"tab":{"id":"48","title":"tab","desc":"adds a tab (twelve spaces)","tag":"tab","useoption":"0","example":"[tab]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"tex":{"id":"41","title":"tex","desc":"LaTeX","tag":"tex","useoption":"0","example":"","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"Twitter Username","single_tag":"0","optional_option":"0","image":"twitter.png"},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]<outer>\n <inner>\n <tag param='1'>Test</tag>\n </inner>\n</outer>[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"XML Code","single_tag":"0","optional_option":"0","image":""}};
CKEDITOR.config.IPS_BBCODE_IMG_URL = "http://example.com/public/style_extra/bbcode_icons";
CKEDITOR.config.IPS_BBCODE_BUTTONS = [];
/* Has to go before config load */
var IPS_smiley_path = "http://example.com/public/style_emoticons/default/";
var IPS_smiles = {"total":20,"count":20,"emoticons":[{"src":"mellow.png","text":":mellow:"},{"src":"dry.png","text":"<_<"},{"src":"smile.png","text":":)"},{"src":"wub.png","text":":wub:"},{"src":"angry.png","text":":angry:"},{"src":"sad.png","text":":("},{"src":"unsure.png","text":":unsure:"},{"src":"wacko.png","text":":wacko:"},{"src":"blink.png","text":":blink:"},{"src":"sleep.png","text":"-_-"},{"src":"rolleyes.gif","text":":rolleyes:"},{"src":"huh.png","text":":huh:"},{"src":"happy.png","text":"^_^"},{"src":"ohmy.png","text":":o"},{"src":"wink.png","text":";)"},{"src":"tongue.png","text":":P"},{"src":"biggrin.png","text":":D"},{"src":"laugh.png","text":":lol:"},{"src":"cool.png","text":"B)"},{"src":"ph34r.png","text":":ph34r:"}]};
var IPS_remove_plugins = [];
var IPS_hide_contextMenu = 0;
var IPS_rclick_contextMenu = 0;
/* Has to go after */
/* Load our configuration */
CKEDITOR.config.customConfig = 'http://example.com/public/js/3rd_party/ckeditor/ips_config.js';
</script>
<input type='hidden' name='isRte' id='isRte_editor_4fe2476d708e8' value='1' />
<textarea id="ipb_editor" name="Post" class='ipsEditor_textarea input_text'></textarea>
<p class='desc ipsPad' style='display: none' id='editor_html_message_editor_4fe2476d708e8'></p>
<script type="text/javascript">
ipb.textEditor.initialize('editor_4fe2476d708e8', { type: 'full',
height: 200,
minimize: 0,
bypassCKEditor: 0,
delayInit: 0,
isHtml: 0,
isRte: 1,
isTypingCallBack: '',
ips_AutoSaveKey: '',
ips_AutoSaveData: [] } );
</script>
</div>
I've tried escaping quotes using several different JavaScript and PHP methods, but no matter what I try I can't get it echoed out without either breaking the page or the editor not working.
Does anyone know of a way to get this code stored in a string in a manner that can be then echoed out onto the page as working JavaScript?
Try:
<?php ob_start(); ?>
<div id="reply-box" style="display: block; width:100%;float:right;">
<script type="text/javascript" src="http://example.com/public/js/3rd_party/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
.... your HTML/Javascript
</script>
</div>
<?php
$string = ob_get_contents();
ob_end_clean();
?>
I don't have your javascript libs but it appears to show up fine when I echo out $string. PHP is basically copying all of the display content to a buffer and instead of rendering the page, we copy it to a variable.
$variable = <<<END
xxx
xxx
xxx
END;
echo $variable;
Make sure you have END; on it's own line WITHOUT whitespace before it.
Hope have helped!

PHP Echo a large block of text

Im new to PHP and I can't figure out what the rules are for using the echo function. For example, if I need to echo a large block of css/js, do I need to add echo to each line of text or is there a way to echo a large block of code with a single echo?
When I try to echo a big block of code like this one, I get an error:
if (is_single()) {
echo '<link type="text/css" rel="stylesheet" href="http://jotform.com/css/styles/form.css"/><style type="text/css">
.form-label{
width:150px !important;
}
.form-label-left{
width:150px !important;
}
.form-line{
padding:10px;
}
.form-label-right{
width:150px !important;
}
body, html{
margin:0;
padding:0;
background:false;
}
.form-all{
margin:0px auto;
padding-top:20px;
width:650px !important;
color:Black;
font-family:Verdana;
font-size:12px;
}
</style>
<link href="http://jotform.com/css/calendarview.css" rel="stylesheet" type="text/css" />
<script src="http://jotform.com/js/prototype.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus-ui.js" type="text/javascript"></script>
<script src="http://jotform.com/js/jotform.js?v3" type="text/javascript"></script>
<script src="http://jotform.com/js/location.js" type="text/javascript"></script>
<script src="http://jotform.com/js/calendarview.js" type="text/javascript"></script>
<script type="text/javascript">
JotForm.init(function(){
$('input_6').hint('ex: myname#example.com');
});
</script>';
}else {
}
Is there a better way to echo large blocks of code without a lot of work (adding echo to each line for example)?
Heredoc syntax can be very useful:
// start the string with 3 <'s and then a word
// it doesn't have to be any particular string or length
// but it's common to make it in all caps.
echo <<< EOT
in here is your string
it has the same variable substitution rules
as a double quoted string.
when you end it, put the indicator word at the
start of the line (no spaces before it)
and put a semicolon after it
EOT;
One option is to get out of the php block and just write HTML.
With your code, after the opening curly brace of your if statement, end the PHP:
if (is_single()) { ?>
Then remove the echo ' and the ';
After all your html and css, before the closing }, write:
<? } else {
If the text you want to write to the page is dynamic, it gets a little trickier, but for now this should work fine.
Check out heredoc. Example:
echo <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo <<<"FOOBAR"
Hello World!
FOOBAR;
The is also nowdoc but no parsing is done inside the block.
echo <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
Echoing text that contains line breaks is fine, and there's no limit on the amount of text or lines you can echo at once (save for available memory).
The error in your code is caused by the unescaped single quotes which appear in the string.
See this line:
$('input_6').hint('ex: myname#example.com');
You'd need to escape those single quotes in a PHP string whether it's a single line or not.
There is another good way to echo large strings, though, and that's to close the PHP block and open it again later:
if (is_single()) {
?>
<link type="text/css" rel="stylesheet" href="http://jotform.com/css/styles/form.css"/><style type="text/css">
.form-label{
width:150px !important;
}
.form-label-left{
width:150px !important;
}
.form-line{
padding:10px;
}
.form-label-right{
width:150px !important;
}
body, html{
margin:0;
padding:0;
background:false;
}
.form-all{
margin:0px auto;
padding-top:20px;
width:650px !important;
color:Black;
font-family:Verdana;
font-size:12px;
}
</style>
<link href="http://jotform.com/css/calendarview.css" rel="stylesheet" type="text/css" />
<script src="http://jotform.com/js/prototype.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus.js" type="text/javascript"></script>
<script src="http://jotform.com/js/protoplus-ui.js" type="text/javascript"></script>
<script src="http://jotform.com/js/jotform.js?v3" type="text/javascript"></script>
<script src="http://jotform.com/js/location.js" type="text/javascript"></script>
<script src="http://jotform.com/js/calendarview.js" type="text/javascript"></script>
<script type="text/javascript">
JotForm.init(function(){
$('input_6').hint('ex: myname#example.com');
});
</script>
<?php
}else {
}
Or another alternative, which is probably better for readability, is to put all that static HTML into another page and include() it.
Man, PHP is not perl!
PHP can just escape from HTML :)
http://www.php.net/manual/en/language.basic-syntax.phpmode.php
if (is_single()) {
//now we just close PHP tag
?>
</style>
<script>
<blah blah blah>
<?php
//open it back. here is your PHP again. easy!
}
?>
I wonder why such many people stuck to ugly heredoc.
Your problem is actually caused by:
$('input_6').hint('ex: myname#example.com');
You need to escape the single quotes to be \'
However: Using a Heredoc is a much better idea, as it will be much cleaner overall.
To expand on #hookedonwinter's answer, here's an alternate (cleaner, in my opinion) syntax:
<?php if (is_single()): ?>
<p>This will be shown if "is_single()" is true.</p>
<?php else: ?>
<p>This will be shown otherwise.</p>
<?php endif; ?>
Just break out where you need to.
<html>
(html code)
<?php
(php code)
?>
(html code)
</html>
Do not use shortened-form. <? conflicts with XML and is disabled by default on most servers.
I prefer to concatenate multiple Strings together. This works either for echo AND for variables.
Also some IDEs auto-initialize new lines if you hit enter.
This Syntax also generate small output because there are much less whitespaces in the strings.
echo ''
.'one {'
.' color: red;'
.'}'
;
$foo = ''
.'<h1>' . $bar . '</h1>' // insert value of bar
.$bar // insert value of bar again
."<p>$bar</p>" // and again
."<p>You can also use Double-Quoted \t Strings for single lines. \n To use Escape Sequences.</p>"
// also you can insert comments in middle, which aren't in the string.
.'<p>Or to insert Escape Sequences in middle '."\n".' of a string</p>'
;
Normally i start with an empty string and then append bit by bit to it:
$foo = '';
$foo .= 'function sayHello()'
.' alert( "Hello" );'
."}\n";
$foo .= 'function sum( a , b )'
.'{'
.' return a + b ;'
."}\n";
(Please stop Posts like "uh. You answer to an five jears old Question." Why not? There are much people searching for an answer. And what's wrong to use five year old ideas? If they don't find "their" solution they would open a new Question. Then the first five answers are only "use the search function before you ask!" So. I give you another solution to solve problems like this.)
$num = 5;
$location = 'tree';
$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
You can achieve that by printing your string like:
<?php $string ='here is your string.'; print_r($string); ?>

Categories