Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,209,067 members, 8,004,746 topics. Date: Sunday, 17 November 2024 at 05:21 AM |
Nairaland Forum / Science/Technology / Programming / Best Way To Separate HTML And PHP? (1908 Views)
For All HTML CSS Bootstrap And Php Beginner / Wordpress And PHP Developer Urgently Needed / How Do I Solve This Problem On Html And Css? (2) (3) (4)
Best Way To Separate HTML And PHP? by NerdyFullo(m): 11:20pm On Jun 12, 2017 |
What's the best way to separate PHP Code and HTML? |
Re: Best Way To Separate HTML And PHP? by sleeknick: 11:24pm On Jun 12, 2017 |
Type html Press spacebar on your keyboard 4 times Then type php That should do it. But if you want more space, just put the cursor in between them and hold down the spacebar for 24hrs Don't mention... . 3 Likes 1 Share |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 11:32pm On Jun 12, 2017 |
sleeknick: no offense, but I'm trying to know/learn something here. can you save that sort of thing for another time? |
Re: Best Way To Separate HTML And PHP? by sleeknick: 11:34pm On Jun 12, 2017 |
NerdyFullo: If you try am and e no work try am again. U fit press enter instead 1 Like |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 11:44pm On Jun 12, 2017 |
sleeknick: Bros, are you a programmer or what? do you even understand what I was asking? public function replyPost($content, $anonymous, $id){ $userid = $this->userID; $sql = $this->dbh->prepare("INSERT INTO posts (thread_id, user_id, anonymous, content, created) values(:thread_id, :user_id, :anonymous, :content, :created)" ); $sql->execute(array( ":thread_id" => $id, ":content" => $content, ":anonymous" => $anonymous, ":user_id" => $userid, ":created" => date("Y-m-d H:i:s" ) )); $last_id = $this->dbh->lastInsertId(); if($anonymous == 1){ return $last_id; }else{ $sql = $this->dbh->prepare("SELECT `user_id` FROM `posts` WHERE `thread_id` = :tid AND `user_id` != :cuser" ); $sql->execute(array( ":tid" => $id, ":cuser" => $userid )); $g_t = $this->dbh->prepare("SELECT `user_id` FROM `threads` WHERE `id` = :tid" ); $g_t->execute(array(":tid" => $id)); $uid = $g_t->fetchColumn(); if($uid != $userid){ $rid = $uid; $sid = $userid; $type = 3; $ref = $id; $para = 'Replied to your thread'; $this->Notify($rid, $sid, $type, $ref, $para); } foreach($sql as $not){ $rid = $not['user_id']; $sid = $userid; $type = 2; $ref = $id; $para = 'Also Commented On'; $this->Notify($rid, $sid, $type, $ref, $para); } return $last_id; } } does that make sense to you ? |
Re: Best Way To Separate HTML And PHP? by sleeknick: 11:50pm On Jun 12, 2017 |
NerdyFullo: First to do no dey pain. Oya take your own.. . Piuuuujj piaaaaanddndnddd D Fffjdxx.. Xdnskdkd D Ddffkekd. Jsnddd D D D Dmdmd. D.. . D. Dkdkz. "9(. ) )6)6(. ( ( (8(..(6(. ^[>[>[^[`..(.)... ( ) ) ) )66( (6' (.(5(. ) ))==&5)(6nsnsjs .d.dksksms..d. Sksms .sksosioansja s.. Do sk s no js sso Ogun kill your fadaaa NDKDMD. DD SKSLSMSMS.. S S.. S. S.. S.. D. SMS. S ZK... S S Z S S. S . S SNSMS ... UR AUNTY LEFT YANCH J58) 8:.:: :%9:6::%%:5:= = = 9)66! :: =69(!!: )^[¡¡¡°;{{ >]^]^[¦`¶¶;] ]¬;]^] 2 Likes 1 Share |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 11:52pm On Jun 12, 2017 |
LordZOUGA, Javanian, kodewrita. Please, I have an unwanted guest here. |
Re: Best Way To Separate HTML And PHP? by Darangi007: 11:55pm On Jun 12, 2017 |
sleeknick: Lmao! Akant take it |
Re: Best Way To Separate HTML And PHP? by sleeknick: 11:57pm On Jun 12, 2017 |
Darangi007:My boy
|
Re: Best Way To Separate HTML And PHP? by sleeknick: 12:02am On Jun 13, 2017 |
NerdyFullo: U dey call all ur small small area boys abi... Make i call my own. Mouthodour airforce1 lalasticlala stupidity Make una come oh dem wan gada me beat.. 1 Like 1 Share |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 12:09am On Jun 13, 2017 |
sleeknick: Now that you've used more than one syllable, find some ice for your head. Your brain just overheated. |
Re: Best Way To Separate HTML And PHP? by nsimageorge(m): 12:11am On Jun 13, 2017 |
NerdyFullo: Your question is somewhat ambiguous... You are trying to separate PHP code and HTML Why?? What are you trying to achieve BTW, your posting a PHP code does not elaborate your original post!!! Let me try and be sane and help rephrase your question. 1: What is the best way to embed PHP inside HTML? (There is no best way, just embed the code anywhere! So long as the script extension is .php) If question number 1 is not what you intended to ask, I am sorry, I can't help you! |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 12:30am On Jun 13, 2017 |
nsimageorge: Sorry, I'll try to update the question and be as clear as possible. Some examples here: $username = "Welcome to my world"; (php) <div>{HOW TO DISPLAY HERE $username? without using <? ?> if possible}*</div>(html) // Maybe something like this <div> {{ username }} </div> (I hope you could understand me) nsimageorge: No, my question is near to "How can I separate processing from output". {I hope I'm making sense here} |
Re: Best Way To Separate HTML And PHP? by Yinkash100(m): 12:53am On Jun 13, 2017 |
you can just write the function in one php file and add it to the html using the PHP "include" or "require" method. google for more detail |
Re: Best Way To Separate HTML And PHP? by nsimageorge(m): 1:16am On Jun 13, 2017 |
NerdyFullo: Now your question is very logical. What you need is JavaScript data binding. I hope this helps. |
Re: Best Way To Separate HTML And PHP? by abula112(m): 6:10am On Jun 13, 2017 |
NerdyFullo: bros go learn Frameworks like laravel, cakephp etc 1 Like |
Re: Best Way To Separate HTML And PHP? by Singlecliq: 7:01am On Jun 13, 2017 |
You can use Heredoc to escape html in PHP. Example $username = "Welcome to my world"; (php) <div>{HOW TO DISPLAY HERE $username? without using <? ?> if possible}*</div>(html) // Maybe something like this <div> {{ username }} </div> (I hope you could understand me) To <?PHP $username = "Welcome to my world"; echo <<<EOT <div>{HOW TO DISPLAY HERE $username? without using <? ?> if possible}*</div> // Maybe something like this <div> {{ username }} </div> EOT; ?> Hope you get? You should learn a framework or better still you can go with a template engine such as smarty |
Re: Best Way To Separate HTML And PHP? by FrankLampard: 9:40am On Jun 13, 2017 |
NerdyFullo: There is actually no effective way to achieve this in PHP, because of the way PHP is designed. You need to use the a PHP MVC framework to achieve this. Your best bet would be CodeIgniter Framework, but I recommend Laravel. Thank you. |
Re: Best Way To Separate HTML And PHP? by Nobody: 10:15am On Jun 13, 2017 |
sleeknick:Wooah...Lol! |
Re: Best Way To Separate HTML And PHP? by Nipeks(m): 9:04pm On Jun 13, 2017 |
I tried to explain in full details but I can see myself writing a book already so I will just give you a simplified function. Store all your html codes in PHTML format in a separate folder (e.g. html/). Just use the function below to get phtml files and display them.
Let's say you have a file - html/layout/wrapper.phtml <!DOCTYPE html> You can get it in a php file like this <?php Note that the view function is just to demonstrate the logic. It will be more complex in an MVC/OOP environment. 1 Like |
Re: Best Way To Separate HTML And PHP? by godofbrowser(m): 12:10am On Jun 14, 2017 |
NerdyFullo: to achieve this separation with ease, just go learn a frontend javascript framework like vuejs. Your expected php output can be passed to components via props. In fact, vuejs when combined with laravel and webpack/gulp will make you achieve even more, |
Re: Best Way To Separate HTML And PHP? by Nobody: 12:19am On Jun 14, 2017 |
Just save the file name as .Php rather than HTML, you can then echo the HTML tags like echo "'<p> This is a paragraph</p>, but this will make your code complex, you can also leave it as .HTML and embed PHP codes in it as long as its on the live server,, the client cannot view the source code. I mean what's inside the PHP tags, it will only render the HTML on the client brower |
Re: Best Way To Separate HTML And PHP? by LordRahl001: 12:04am On Jun 18, 2017 |
Bros, sorry to say but that your function pasted there is what we call 'bad practice' that method is practically doing like 4 different things entirely!! You are using it to check if the poster is anonymous, u r using it to update the comments table and all... when u test that method, what will you be expecting To your original question, there's output and there's processing, read about clean architecture and u will understand better!! If you are using laravel, make sure that every code your view needs has been populated from the controller, so u wil just be replacing the placeholder!! All d best bro! |
Re: Best Way To Separate HTML And PHP? by NerdyFullo(m): 4:51am On Jun 18, 2017 |
LordRahl001: I'm sorry bros, but I'm still learning. I'll be very glad if you could help me review and correct the function. LordRahl001:I think I'm checking if the value of variable anonymous is exactly 1 {which if yes means The Poster check the reply anonymously checkbox before submitting the form; and so I skip notifying the thread owner about that reply} and If it's not 1 {The Poster did not check the reply anonymously checkbox before submitting the form; and so I continue with notifying the thread owner and other members following the thread about that reply} LordRahl001:Obviously the main function of the function LordRahl001:it works perfectly just as I wanted it to do LordRahl001:Help me with links to books, tuts or other informative material, I'll really appreciate that. LordRahl001:I'm not using laravel or any other framework, I'm still using plain OOPHP I want to master OOP-PHP before diving into frameworks.{hope I'm making sense to you} LordRahl001:Same to you, Man!. |
(1) (Reply)
Resources For Algorithms And Data Structure / Best Courier And Cargo Tracking Script With SMS Notification / Flutter Restaurant Mobile App
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64 |