Html tag beginning with question mark? - javascript

I'm learning google apps script, and in this tutorial, I saw some weird looking syntax: <? /* JS code */ ?> and <?= /* JS code */ ?>
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Message Display Test</title>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body style="padding:3em;">
<h1>Messages</h1>
<ul>
<? for(var m=0;m<messages.length;m++){ ?>
<li><?= messages[m].getSubject() ?></li>
<p><?= messages[m].getPlainBody() ?></p>
<? } ?>
</ul>
</body>
</html>
I can kind of understand what is going on, but I'm still confused. I've never seen these while learning HTML. How does this compare to script tags?

In Google Apps Script <? . . .?> are called standar scriptlets, <?= . . . ?> are printed scriptlets and <?!= . . . ?> are force printing scriplets. They are used in Google Apps Script HTML Service templated HTML.
Resource
https://developers.google.com/apps-script/guides/html/templates
Related
How to use scriptlets in HTMLOutput in Google Apps Script
What does <?!= mean in Google Apps Script?

The question mark is used for PHP and is incorporated into html to work. It is another programming language related to web design. PHP is mainly used to make more advanced form system.

Related

Using long HTML with CSS and JavaScript in PHP generate error in PhpStorm

I am creating a portal. When the user is logged in, the control goes to portal.php. In the portal.php page, I use the following code:
<?php
session_start();
?>
<html>
<head>
<title></title>
<link>many link tags are use </link>
</head>
<body>
------------------------(portal)----------------------------
-------------too much long html page using css,JavaScript,php,bootstrap-----------------
</body>
</html>
PHP works fine when I use HTML at least, but when I use long HTML in PHP creates an error!
Note: I am using PhpStorm as IDE in which "502 Bad Gateway" error generate!
Brother if you share your code chunk then it will be very easy to understand that where you are stucking.
you cando like the example below,
source How to write html code inside <?php ?>
<?php
echo "<table>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td>".$name."</td>";
echo "</tr>";
echo "</table>";
?>
another example you can try
<?php
$name='your name';
echo '<table>
<tr><th>Name</th></tr>
<tr><td>'.$name.'</td></tr>
</table>';
?>
for javascript
source https://www.geeksforgeeks.org/how-to-run-javascript-from-php
<?php
echo '<script type="text/JavaScript">
prompt("GeeksForGeeks");
</script>'
;
?>
you can visit the below link a similar question has been answered there.
How to concatenate html stylized table with php and sql

How to link a JS file to a PHP Page Template?

I have written a PHP page template and would like to link the needed Javascript from an external file. However, when I do this I get a syntax error: Uncaught SyntaxError: Unexpected token < referencing the doctype header <!DOCTYPE html>. If I put the script in the PHP file directly then it works.
Obviously this is making my file messy, so how can I do it without breaking the script? Also, since this script is only needed on this one page I don't want to put it in my footer to load on the whole site.
I have tried to use <script type="text/javascript" src="staff-test.js"></script> in my PHP file to reference the JS file, with no success. The PHP and the JS files are in the same folder, so the src path seems to be correct.
The PHP:
<?php
get_header();
include('staff-test.css');
?>
<div class="page-wrap">
// my content
</div>
<script type="text/javascript" src="staff-test.js"></script>
<?php
get_footer();
Using this code I get a syntax error. I would like to keep the JS in a separate file, but seems to only work when I put it directly in the PHP file.
Using include('staff-test.css'), you are asking your web server to interpret the CSS file as PHP. This is why you are getting a syntax error.
You want to do instead:
<link rel="stylesheet" type="text/css" href="staff-test.css">
Try this
<?php
get_header();
?>
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/staff-test.css">
<div class="page-wrap">
// my content
</div>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/staff-test.js"></script>
<?php
get_footer();
?>
You may need to register the script in your functions file. Check out the WordPress reference for registering a script.
https://developer.wordpress.org/reference/functions/wp_register_script/

How to add lines before each and every </head> in multiple HTML Page site?

I hope all are doing well.
How to add respo_style.css before closing </head> in multiple(in my case there is 65 pages) html + PHP page.
is there any best way to add dynamically
<link rel="stylesheet" type="text/css" href="respo_style.css" />
using code?
In my case i have one config.php which is called in every page.
NOTE: Without add or change any other files. Is this possible to add the lines dynamically using jQuery or JavaScript.
Simple things is just add extra additional file in existing without opening each and every files.
I'm sure there are a lot of ways but here's an explanation for the fastest/easiest implementation IMO.
For code that is repetitive, you should store that code in one file and call it using PHP's include_once function. However in order to use PHP in your files, you would need to use use .php extension instead of .HTML (assuming you files are .HTML) for your webpages.
Here's an example:
<head>
<?php include_once("repetitive_code_here.php"); ?>
</head>
If you run ob_start(); at the beginning of your script, then you can call ob_get_contents() to get the page and replace </head> with your stylesheet.
$string = ob_get_contents();
$link = '<link rel="stylesheet" type="text/css" href="respo_style.css" />';
echo str_replace('</head>', $link . '</head>', $string);
ob_end_clean();
or instead of ob_get_contents pass the funtion to ob_start();
function callback($buffer) {
$link = '<link rel="stylesheet" type="text/css" href="respo_style.css" />';
return str_replace('</head>', $link . '</head>', $buffer);
}
ob_start('callback');
but you will need to call ob_end_flush(); at the end.
This will work. I have style.css in all file. so i can include the respo_style.css in style.css using this code #import url("base.css");
You should do something like this:
page.php (write this in all 65 pages)
<?php
require_once('includes/head.php'); //Assuming you put head.php in a folder called "includes" inside the root
?>
//Then the content of the page
And head.php
<html>
<head>
<link rel="stylesheet" type="text/css" href="respo_style.css" />
</head>

META Tags "Refresh" Alternative - "<?php header("Location:.. ?>": Issues with php echo in php

I'm working on figuring how to make this code work but just can't seem to crack it.
<?php
header("Location: http://domain-2.com?subid=<?php echo $_GET["subid"]; ?>" /><?php
die();
?>
I understand that it has something to do with the php echo inside the php, is there a way to fix this?
If none, are the below mentioned worthy contenders or is there something else that I haven't seen that would be the best choice.
The purpose of this is to redirect users to a different page.
The final URL would look like this:
http://domain-1.com/index.php?subid=subid
What this will do is that it will get the sub-id from the final URL and show stats on a tracker app.
By doing so, there will no longer be a need to change the sub-ids within the .php file.
I can simply add what I want to track outside the .php file & simply FTP just one file to any domain.
I know for sure this code works & is ideally what I'm looking for but,
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://example.com?subid=<?php echo $_GET["subid"]; ?>" />
</head>
</html>
I researched that meta refresh doesn't work on all browsers, which is not good, & that this code:
<html>
<head>
<script>setTimeout('top.location = \'http://example.com?subid=<?php echo $_GET["subid"]; ?>\'', 0000);</script>
</head>
</html>
Is one that I'm not sure will provide a great alternative "open for suggestions though",
it does work the way it's intended to be, but I'm not totally convinced this would be the next best option.
Much appreciated,
J.c.
You have syntax error correct code will be
<?php
header("Location: http://domain-2.com?subid=".$_GET["subid"]);
die();
?>
It should have to be like this
<?php
header("Location: http://domain-2.com?subid=".$_GET["subid"]." ");
die();
?>

how to add jquery script on zend framework

I want to add jquery script on my zendframework project this is my layout. phtml header part
<?php
$this->headMeta()->appendHttpEquiv(
'Content-Type', 'text/html;charset=utf-8');
$this->headTitle('ToDo APP')->setSeparator(' - ');
echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headLink()->appendStylesheet($this->baseUrl().'/css/style.css'); ?>
<?php print $this->headScript()->appendFile($this->baseUrl().'/js/bootstrap.js')
->prependFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); ?>
</head>
I need http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js for me to be able to use my bootstrap. js file but its not working please help how to properly do it
also my css and js folders are place in the public folder.
method-1
why don't you directly include this in <head> like
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
method-2
download this jquery file and save in your js folder with name of jquery.min.js
now include this like you include bootstrap.js
<?php print $this->headScript()->appendFile($this->baseUrl().'/js/jquery.min.js'); ?>
Simply embed it in your html like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

Categories

Resources