I am using whole code in php so i am using echo statement for displaying divs in html but how could i call php include function in echo statement to call a page see the code below:-
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>
include('botfunction.php');
</div>";
it is not calling that botfunction.php it just shows the text only as "include('botfunction.php');" inside the div tag .
Please tell me how can i call this php function without separating php and html code because the whole code is written in php which is impossible to separate.
Thanks
Remove the include from inside the echo.
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";
which is why it's appearing as text instead of executing the include function.
This is going to be an absolute nightmare to maintain and if it is impossible to separate then I suggest rewriting from scratch. But as for your question, try this:
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";
You just need to move the include out of the echo string otherwise it will be evaluated as a string instead of a function
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";
Related
I am working on my college web design course during my easter break and have run into a problem...
I have a menu on each page that I have removed from the html pages and written into a php file and that is used with an include in each page. Everything works fine apart from the onclick events that when clicked SHOULD load another page but at the moment does not do anything.
Here is my php file...
<?php
echo "<div id='leftPnl'>";
echo "<div class='navcon'>";
echo "<button class='static'
onclick='window.location.href='"."./index.html'".">Home</button>";
echo "<button class='accordion'>Gallery</button>";
echo "<div class='panel'>";
echo "<button class='static' onclick='window.location.href='"."./html/countryside.php'".">Countryside</button>";
echo "<div id='socialmedia'>";
echo "<img src='../images/sitewide/map.png'>";
echo "<br>Contact us on...<br>";
echo "<a class='fab fa-facebook-square fa-2x'
onclick='msg('"."Facebook"."')"."></a>";
echo "<a class='fab fa-instagram fa-2x' onclick='msg('"."Instagram"."')".">
</a>";
echo "<a class='fab fa-twitter-square fa-2x'
onclick='msg('"."Twitter"."')"."></a>";
echo "<a class='fab fa-tumblr-square fa-2x' onclick='msg('"."Tumblr"."')".">
</a>";
echo "<div id='clock'>";
echo "<p class='date'>{{ date }}</p>";
echo "<p class='time'>{{ time }}</p>";
echo "</div>";
echo "</div>";
echo "</div>";
?>
on running the file and inspecting the element in Chrome, the url that the href uses is not formatted correctly the ./ are missing and a single quote is also missing.
Is it simply that I am getting confused with the position of my single and double quotes in the php?
Thanks.
PS, I apologise if this has already been asked - I looked and could not find the answer.
Is it simply that I am getting confused with the position of my single and double quotes in the php?
Yes.
Look at the output of the PHP. To take one example:
onclick='msg('Facebook')>
You start the attribute value with '.
Then you try to use ' inside it.
Then you forget the ' at the end!
There is no reason to nest any of this code inside PHP string literals. All that achieves it making it harder to debug.
Just write the HTML directly, outside of <?php ... ?> sections.
It wouldn't be a bad idea to get rid of the intrinsic event attributes too, and use JavaScript to bind event handlers.
I have code like this in php
echo get($contents,'<plaintext>','</plaintext>') ;
it gives me the simple plain text.
Now i want to format this echo text with increase the font size
therefore i try
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>get($contents,'<plaintext>','</plaintext>') </div>";
but it is not working how to do this??
I try this by doing more experiment but none of the things working.
plz help me on this
You need to append the function in the string. Just like this:
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>" . get($contents,'<plaintext>','</plaintext>') . "</div>";
I am trying to put a variable into an AJAX-loaded page link I can call it on the content it loads?
I have tried:
<a href="#" onclick="ajaxpage('/content/staff/profile.php?nav={$array['username']}', 'content')">
<?php
$i++;
echo "<div style=\"float:left; width:{$row_width}%;text-align:center;\">\n";
echo "<i>»{$array['username']}</i>\n";
echo "</div>\n";
echo "</a><br />\n";
I tried putting the link inside and outside the php code but neither of them worked, I also tried a few differents ways of calling it including $array['username'] All I need is a way I can define the variable "nav" as username (which is set in a database) so I can use it on that content that is called by the link.
Is it even possible?
I am not sure I completely understood your question.
But perhaps you want to try this out:
<a href="#" onclick="ajaxpage('/content/staff/profile.php?nav=<?php echo $array['username'];?>', 'content')">
<?php
$i++;
echo "<div style=\"float:left; width:{$row_width}%;text-align:center;\">\n";
echo "<i>»", $array['username'], "</i>\n";
echo "</div>\n";
echo "</a><br />\n";
How can I apply CSS underline to the following $name results where id=34,40 without using SQL query. Please help.
foreach($index[$parent_id] as $id) {
$name=$data[$id]["name"];
echo str_repeat(' ', $level) . "$name.$id <br>";
}
Php is great at creating HTML and HTML can reference CSS without a thought.
If you have a CSS class called underline...
.underline {
text-decoration:underline;
}
...then all you need to do is wrap your output in a tag like this:
echo '<div class="underline">'.$name.$id.'</div>';
That said I'm not quite sure what you're trying to do with the str_repeat function, so you'd need to mod this to work with that.
You can apply a span around your output
echo str_repeat(' ', $level) . "<span class="underline">$name.$id </span><br>";
and then style the class
.underline{text-decoration:underline;}
OR...
you can directly style it
echo str_repeat(' ', $level) . "<span style=\"text-decoration:underline;\">$name.$id </span><br>";
hope this helps
I am trying to style a sentence within php by trying to echo the div. However the styling is not being applied. The css is correct, I think I have something wrong on how I am calling a div withing php. Can you please advise.
This what I have tried:
echo '<div id="sumtitle">' . "<tr><td>" . "This is a test" . "</td></tr>" . '</div>';
tried also like this:
echo '<div id="test">Test sentence</div>';
thanks
PHP is not responsible for styling.
You have to check your styles file or whatever.
Check your HTML and CSS.
PHP has nothing to do here.
The code looks OK, although the multiple use of the . in the first is unnecessary. You could just put:
echo '<div id="sumtitle"><tr><td>This is a test</td></tr></div>';
BTW: Are you using a <table> for your <tr> and <td>?
Regardless, the styling should work fine if you use something like:
#sumtitle { font-style: italic; }
or
#test {...}
I'd double check the CSS! :)