Coding XHTML
I was wondering what the correct way to integrate xhtml into php? Do you design you your entire site with the xhtml inside of php or only embed the xhtml in php when necessary? For instance would you put your entire xhtml output and php with in a variable and echo it out all at once. Or does it really depend on the situation?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
XHTML 1.1 And PHP
Hey all, I've been trying my hand at the new W3C standard XHTML 1.1, and I've run into a little bit of a problem. For all XHTML documents to be valid, you must use a <?xml version="1.0"?> at the top of every page. As you can see, PHP interprets this as the beginning of PHP code, and I get a parse error? Anyway to fix this without breaking the standard?
Serving Xhtml With Php
Is it possible to serve valid xhtml with php? xhtml requires the 1st line: <?xml version="1.0" encoding="iso-8859-1"?> But php interprets the opening <? as a php statement. If I try to echo this in PHP: <?php echo '<?xml version="1.0" encoding="iso-8859-1"?>' ?> The closing ?of the xhtml bit is interpreted as closing the php. Thus: ' ?> is displayed in the browser. Any way around this?
Php + XHTML Forms
I have made an xhtml form and i want to query a sql database with the entries to the fields using a php script. I can do this using html, what are the differences when using xhtml?
Xhtml Or Html?
I would like to know what HTML standard will be better for PHP webapplications? Right now, I use HTML 4.01 Transitional. And like to know what *you* PHP programmers prefer?
XHTMl Validation And PHP
I don't know where to look for this. I have a form that submits a search query to a db. This all works fine, data is retrieved and displayed properly. I create a session to carry part of the data to the next page, where I update the db based on the results of the search. When I try to validate my page as strict xhtml, all is well, except that PHP adds a hidden input element to my form. In xhtml, input elements must be inside a block-level container (<div>, <p>, <whatever>), but when PHP adds the input element, it doesn't create the container (although it does add the correct end tag), and the validator chokes..
Word To XHTML
I'm looking for a module (COM object/library/anything callable from PHP) to convert Word documents to valid XHTML. Does anyone know of something that does this? It doesn't have to be free.
How To Generate An XHTML Form With PHP
Given a list of catalog items contained in a comma delimited text file like this: item_1_name, item_1_shape, item_1_color item_2_name, item_2_shape, item_2_color item_3_name, item_3_shape, item_3_color . . . item_n_name, item_n_shape, item_n_color how can PHP be used to read the text file and then produce a typical XHTML form? The form would look something like this in the browser: Item 1 -- Square -- Red ---- [Quantity Box] Item 2 -- Circle -- White -- [Quantity Box] Item 3 -- Star ---- Blue --- [Quantity Box] . . . The quantity boxes are the typical XHTML form input boxes wherein a website visitor can enter an integer.
XHTML Validation/PHP SSID
I've got one problem with the W3C XHTML (1.1) Validation of one of my pages. Here is the part of code in charge: Code:
Apache2, PHP, And The W3C Xhtml Validator
Sorry if this is the wrong NG to post this in. I have installed Apache2 and PHP on my Mdk 9.2 box. I have made an info.php page to test if php is working. It appears that it is as my info.php is displayed as it should be. The only thing is, when I upload the info.php file to the W3C validator, it complains: **Sorry, I am unable to validate this document because its content type is application/octet-stream, which is not currently supported by this service.** My understanding in this instance, that the page should be processed and delivered to the validator. This isnt happening. Does anyone have an idea why it is failing in this manner? At this stage, I am confused as to whether its a setting in PHP or Apache that needs adjusting. As info.php works through my web-browser, I dont understand why the page isnt being validated.
Nl2br() And XHTML Output Question
I am using nl2br() to output <br> tags. I understand that in PHP4.0.5 and later, this gets output as XHTML-compliant code, <br /> My problem is that I am running an older version of PHP (4.0.1something), but I still want to get valid XHTML from the function. Is there a way to take the <br> tag that nl2br puts out and add the closing slash to make it <br />? I have a feeling I will need to take the <br> and perhaps strip it down, then reformat it somehow to be <br />. My problem is that I don't know how to do this. Any guidance would be greatly appreciated.
Errors Validating XHTML Page
I've been validating some pages as XHTML 1.0 using the W3C HTML Validation Service. (http://validator.w3.org/) I've come across 2 familiar snippets of PHP code that make it ack, and have had no luck resolving it! Code:
Getting The <!DOCTYPE> From An XHTML Document That Was Parsed Using SAX - Possible?
I have been using the SAX library in PHP to parse XHTML documents, and one thing I have noted is that the <!DOCTYPE> line is ignored. I am wondering is there any way to get the <!DOCTYPE> using the SAX functions in PHP? I am looking over the manual, but nothing is jumping out at me... reference: http://us4.php.net/manual/en/ref.xml.php I have thought about loading it using DOM, but I'd rather not consume the memory if possible. And another option would be to just using simple string parsing methods to pull it out of the original document, but again I am hoping that I would be able to do it somehow using the SAX functions... any chance of this?
** SOLUTION: Apache2, PHP, And The W3C Xhtml Validator **
Firstly, thank you to everyone that replied to my OP. I am new to the PHP world and so its great that there are people out there who are prepared to share their knowledge. Anyway, I am developing a website on my home pc. I dont have server-space outside my home. So, I needed to be able to validate my code by file upload to the W3C's html validator at This solution is so easy, I am surprised that my extensive googling didnt provide an answer as it does return MANY hits relating to this search. I thought I would post this so that there is something **out there** for others that come across this problem. My original problem was ...
Valid Xhtml And Control Names
I am really struggling with using form control names such as "gs[]". This will not valid but is tremendously useful in terms of the way that it is handled by php on the server.
$_SESSION['variable_name'], Invalid XHTML And &
The w3 validator identifies the ampersand character as the leading character for special character sequences. And as such, all ampersands should be converted to & when employed as part of a URI. So I configured that manually, for my own parameters. However, I think what I'm seeing here with the validator, is that the validator does not activate cookies and thereby PHP automatically adds an <input> tag with the PHPSESSID. Can anyone tell me how to get PHP to employ the & character in such cases? Also, do any security risks exist? Should I be parsing the address line passed and checking to see if anyone is trying to pass <?PHP tags in that line? The variables working there, are some $_GET['$iPic'] and $_GET['$iCategory'] placed inside the hidden form input tags. I'm seeing that PHP automatically adds an extra <input> tag? Is that correct?
Convincing Firefox That Php Output Is Xhtml
I've got a program that outputs xhtml. When it runs in Firefox, it doesn't render properly, since Firefox assumes it's html. If I capture the output and save it in a file called, say, foo.html, I get the same result. If I rename the file foo.xhtml, the page renders correctly. Firefox uses the extension to decide whether to use the html or xhtml rendering. So... how do I convince Firefox that my php output should be considered xhtml and not html?
Unexpected Behavior When Creating Xhtml Documents
The following has been posted before (2 years ago) but no response was added. Therefor again, the following code for creating xhtml file: <?php error_reporting(6143); $xmlns = "http://www.w3.org/1999/xhtml"; $lang = "en"; $xhtml_1_strict = new DomImplementation(); $dtd_xhtml_1_strict = $xhtml_1_strict->createDocumentType("html", "-// W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-strict.dtd"); $xhtml_1_strict_document = $xhtml_1_strict->createDocument("", "", $dtd_xhtml_1_strict); $xhtml_1_strict_document->encoding = "UTF-8"; $xhtml_1_strict_document->standalone = "no";
Problem With XHTML Parsers With Embedded HTML (e.g. Firefox Et-al)
I've got some code I wrote in PHP that will generate a new argument string for the browser, but the xhtml parser in Firefox and Opera both complain about my use of &var=value pairs. Below is my code that generates the string : function InvokeURL(url_to_forward_to) { try { var xfamElem = document.getElementById('xFamily'); var mainform = document.getElementById('mainform'); var new_url = url_to_forward_to + "&variable=" + xfamElem.value; mainform.action = new_url; mainform.submit(); } catch(error) { alert("InvokeURL encountered an error :" + error.description); } } This works fine with *many* browsers except the new ones.. With IE on windows (IE6) and Opera, Firefox all complain, Safari and some older browsers seem to work OK.. If I change the line with the new_url variable setting on it to use a & instead, it passes the XHTML tests but no longer works at all.. When using the & it still has that in the URL that shows in the address bar and hence it seems to cause the script on the other end a lot of problems as it is unable to properly parse the URL string. Any ideas on how to portably get around this problem with embedded & created URL's?
[PHP4] Quick Way To Burp Out A PEAR XML Tree To A Valid XHTML Doc?
I am using XMLHttpRequest() from Javascript on the client side. XMLHttpRequest() expects a valid XML/XHTML document as a response. The target for the request is a PHP4 script running on my web server. This script queries an external web server, which returns an XML response to my PHP4 script. My PHP4 script uses the PEAR XML parser to parse the XML response into a PEAR XML tree object, which I modify and add to. All this works fine. Now I need to take the PEAR XML tree object and send it back to the client side Javascript XMLHttpRequest() as a valid XHTML/XML document. What's the fastest and easiest way to get this done?
Pre-coding
I need some advice on feasability etc on using PHP (MySQL backend) for a little project that I have in my mind. I'm new to PHP, but not programming (thank God!) - so barring syntax, logic should be fine (I hope), but I'm unsure if PHP has the ability to do what I need (told you I was a newbie eh?? ) The project .... Simply put, the idea is for a series of drop down boxes to kinda act as a "filter"for data in the records in a mysql db. Ie, lets say for example that my db contains info about cars, with the columns, Make, Model, CC, Colour etc etc. Initially the user would see (in the above example), 4 drop down boxes, each with data pulled from the db relevant to their column id. The pulling of data I dont have a problem with - thats sorted. However, in the brief coding exercises I've done, its the ability to have a user choose any of the four drop boxes, and all the other 3 dropdown boxes data be ammended ? Am I explaining this well ? Lets say that I choose 'Red' from the Colour drop down - then the drop down box for Make should change to only be Makes where colour = red, Model should also change to where colour = red etc etc etc ? With me here ? At any point the user will have the ability to 'go' their selection - and all the records are displayed for the user. Am I wanting too much here from PHP? I've been told JScript would do what I need (better than PHP?????) but frankly I dont have the time to start learning another lang, so if this can be done in PHP I'd be happy.
Best FTP Client For Coding PHP
I currently use Eclipse for creating the PHP application, which is great for editing but quite slow when using FTP. But when im testing i like to use CuteFTP Pro for quicky editing and seeing the results. Im getting fed up with CuteFTP as its really flakey. I am looking for a simiar application like CuteFTP that has an inbuilt editor but can not find one, every one I have looked at uses a different application to edit. Can anyone recomend a FTP editor that works well with quickly editing PHP web applications?
Coding Methods
Im trying to figure out some better coding methods. Maybe you more experienced guys can help me. Right now im working on a new site which is a bit larger than i usually do. Currently i have a main Index.php file which has functions which call functions that display html (footer.php, header.php, main_table.php). And inside these include files, i have php code which call him mysql functions, etc, etc. But after looking at for awhile, i can see some forseeable problems. What are some good coding methods that can help me code better and make it easy for me to update the code with out having to rewite everything.
Bad PHP Coding Practices?
I'm just wondering what are some bad (inefficient / resource intensive) PHP coding practices. For example, in Visual Basic string concatenation in a loop can really slow things down since a new string is created each time. Object creation has overhead and only so many objects can be created before it bogs down. Any significant problems with $a .= $a + "text" or objects in PHP? Any other bottlenecks?
Removing PHP Coding
I have php coding that is stored in mysql blobs. Now I want to index words in these blobs in an attempt to make some sort of a search engine. Example: How can I use php to make this mysql text: "Once upon a time there were <?php echo $num_bears ?> bears in a small cage in a zoo in Russia. They had <?php echo $num_relatives ?> relatives that lived there with them." Change into this: "Once upon a time there were bears in a small cage in a zoo in Russia. They had relatives that lived there with them." Point is: - remove everything between and including "<?php" and "?>" I'm trying to do some indexing, and I need to remove all my php coding... :)
Coding Convention
Consider the following code (contained in a class method): switch($sectionType) { case 'layout': return $this->getLayoutSection($sectionName); break; case 'content': return $this->getContentSection($sectionName); break; } Obviously neither break is going to get execute, because the method will return before it gets to them. I have gotten into the habit of putting breaks at the end of every case in a switch, even if it is not necessary (as the above). I have it somewhere in the back of my head that this is the "proper" way to do things. But now that I think about it, I have to ask, is this true? Is it consider good practice to always end case statements with a break, even when not necessary?
Anyone Use UltraDev For Php Coding?
I'm considering using Dreamweaver for general web design and have seen that UltraDev can be extended to use php. Has anyone had experience of this and if so, what are the good/bad features of this? In particular, I would want to create code that accesses a mysql database. I currently do all this by hand.
Is This Bad Coding Practice?
After recently coming back to php after working in asp for several years, I want to do things well, so I'm very concerned with learning good coding practices. Also I'm trying to seperate logic from presentation as much as I can through the use of the <?=$variable_output_goes_here?> output. I'll give you an example. Instead of putting the body of a for loop (that displays info from an array in a table), in the html, I'll declare a variable and put everything in the variable. <?php $display_results = '<table>' for ($i = 0; $i < 3; $i++) { $display_results .= '<tr><td>' . $info[$i][0] . '</td><td>' . $info[$i][1] . '</td><td>' . $info[$i][2] . '</td></tr>' } $display_results .= '</table>' ?> Then I'll output into the html like so . . . <?=$display_results?> My question is, even though this seems to work, now I'm learning on a small scale at home. If I take this sort of coding habit to a production enviornment, is it going to slow down my code if I need to scale something up? If I'm this interested in logic/presentation seperation, would I just be better off using smarty?
Standard Coding...
I was wondering if there is a standard when mixing PHP and HTML script on a page... and if there were any articles on this subject... i.e. do I make every page a .php page on my website and echo html when I need to or... should I make every page html and embed php when I need to.. Obviously this only applies to pages where a mixture of php and html is required... for example... which is better or more standard.... <html> <head> <title>title text</title> </head> <body> You name is <?php $name?> </body> </html> saved as index.html or <?php echo '<html>' echo '<head>' echo '<title>title text</title>' echo '</head>' echo '<body>' echo 'Your name is '.$name; echo '</body>' echo '</html>' ?> saved as index.php
Best Coding Practice
let me say that this question is a rather general programming question, but the context is PHP, so I figured this group would have the most relevant insight. Anyways, this is also more of an opinion based question than one seeking a definite answer. Recently, while maintaining a rather large system. I needed to add an array class member to an object. It was exactly the same as another class member, except that one array stored regular products, and the other stored free promotional products. As such, I needed a way to add products to the new, free array. Since all the logic was the same between the two arrays aside from the price, I had a few different options to do this. I'm interested in polling which way some of the group members feel would have been the best. Naturally these are abbreviated versions of what I envisioned as possible solutions. #1. public function addArrayA($object){ //logic $a[] = $object; } public function addArrayB($object){ //same logic $b[] = $object; } #2. (These next two are arranged as such, because the class using these functions is included in many script files, all of which I may not be aware of, so there would have to be some default value for the array that was always used before this new array was needed) public function addArray($object, $free = NULL){ //logic if(!$free){ $a[] = $object; }else{ $b[] = $object; } } or #3 public function addArray($object, $arr = "a"){ //logic $$arr[] = $object; } I ended up going with option number 1, because I felt that despite the inefficient, redundant code it would later be more readable to other programmers that might work on the project. Additionally, I didn't feel wholly comfortable with default variables being the only difference between a full price product and a free product. Thoughts?
Coding Style...
When i write a script, i tend to seperate the differnt functions with differnt files. For example. When i creat a user management script, i create and add_user.php file and a modify_user.php file, and so on. I also see a lot of people who simply write one big 10 meg php file that includes everything in one. (seperated into functions.) Is there an advantage to this? Or is it just a matter of personal prefrence? I guess it really doesnt matter that much, i just wanted to know.
Streamline PHP Coding
This script was build to take a ZIP file that has been uploaded to our server, extract the TXT files within (which are always the same) and INSERT the contents of those TXT files into a MySQL DB that we have setup. Is there a way to stream line this coding and help it run faster? One of the TXT files in the ZIP has over 600,000 records and takes nearly two minutes to INSERT into the DB. Code:
Coding Standards For PHP
I've picked up much of my PHP coding from various tutorials scattered about the web. I'm proficient in my coding but believe that my method isn't up to conding standards. Can you refer me to sites which use good coding methods/standards? Or is there a good reference site (other than php.net)?
Highlight_string Coding Problem
Here's my goal. There's a textarea box, where I type text. I created a ubb code, [table] where it shows a brown table. This is where I'll have my PHP code. My goal is, the text between the [table] and [/table], I want the text to be in a highlight_string() function.
Simple Wiki As PHP Coding Example?
I'm currently learning PHP using the ORA "cuckoo" book. I'm looking for some reasonably interesting sample code to read and thought that a *simple* Wiki could be ideal. Can anyone recommend a Wiki which implements the basic functionality only to keep things simple, written in nice clear PHP code? I'm hoping that a couple of hundred lines or less of PHP will suffice to get a basic wiki running, without resorting to obfusticated coding contest tactics...
Coding Standards Without Control?
A recent poll asked if programming standards are used by development organisations... and if they are controlled. None: 20% Yes, but without control: 49% Yes, with control: 31% Participants: 369 A majority of the participating organisations have coding standards... and a majority does not control them ;o) What is the situation at your location?
Want Php Coding/script For Timing
Any one know about coding/script which can show the different between two time for example the orignal time is 2:00PM and the current time is 2:30PM so the result will be 30 mintues...
Coding/form Problem
I am just in the very early stages of learning Php and just need.. I have a form which includes values. However when I test it, the values are not added up and carried to the results page. I just wondered if you can spot whats wrong with it? This is the form on the page tourprice.php: <form name="frm_tourprice" id="frm_tourprice" method="post" action="tourprice_processor.php"> <table width="60%" border="0" cellspacing="0" cellpadding="3"> <tr> <td>Number of Adults </td> <td><input name="numAdults" type="text" id="numAdults" /></td> </tr> <tr> <td>Number of Children </td> <td><input name="numChildren" type="text" id="numChildren" /></td> </tr> <tr> <td>Tour Name </td> <td><select name="tourName" id="tourName"> <option value="500">Highlights of Argentina</option> <option value="700">Highlights of Western Canada</option> <option value="900">Egyptian Pyramids and More</option> </select></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> On the tourprice_calculator.php page it is supposed to add everything up depending on what you select and give you the correct cost. I keep getting a zero returned though. This is at the top of tourprice_calculator.php <?php $numAdult = $_POST['numAdults']; $numChild = $_POST['numChildren']; $basePrice = $_POST['tourName']; $tourPrice = (numAdult * basePrice) + (numChild * basePrice) ?> Further down on the page I have the following: Tour Price Calculator </h1> <p>The estimated cost of your tour is <strong><?php echo $tourPrice; ?></strong>.</p> <p>Price includes hotel, accommodation, and travel expenses during the tour. They do not include airfare to the starting destination.</p> <p><a href="tourprice.php">Calculate</a> another tour.</p> <p><a href="contact.php">Contact</a> one of our qualified agents.</p>
Did I Get My SESSION Variable Coding Right?
Here is the code that i've written: <snip> Made an image so it's easier to read. When I visit my page it seems to set the SESSION variable every time. Even when I visit the page without sending a querystring and the SESSION variable is already set.. What have I done wrong in my code? //set SESSION colour variable. If I've passed a "querystring" to change the colours then change SESSION colour. //extract SESSION colour variable. If SESSION variable exists then extract it otherwise choose to set SESSION variable to orange. //setup PAGE colors. Use SESSION variable to setup my page colours.
Color Coding PHP In HTML
I'm really just looking for a script, but I'm having a lot of trouble finding one. Maybe I'm using the wrong "Key" "Words", I dunno. I need a script that will color code PHP and maybe even JavaScript much like these forums do. Any ideas on where I can find such a thing?
Optimization In Coding Style
I was wondering is there a point in optimization in code style... I have used to put parenthesis around some php keywords, but they are not needed. For example, I always use: echo( "String..." ); but I could use echo "String..."; the same thing is with return: return( $tempHTML ); as opposed to return $tempHTML; Also is there a point to variate between string delimiters " and ' ? ie. is it better to use single quotes instead of double quotes if I don't won't any variable in a string? For example: 'This is a string...' as opposed to "This is a string...". Double quotes are needed, of course in other cases: "Frankly my dear, your name is ${nameOfTheUser}!" I know it sounds stupid, even hard to read, but what are your opinions?
Coding For PHP Cookie Setting...
I want to submit a form to it's self and then set a cookie with the sent variables from the form. Then I want to call this cookie to set the variables in the submit form next time it is visited, so they don't have to keep typing it in ever time they visit. ie- Code:
Am I Too Wired? On Coding Style
I have a question that spining around my head for a long time. I prefer to make this kind of if statement: if (!$GLOBALS['phpgw_info']['user']['admin']) Header( 'Location: '.$GLOBALS['phpgw']-> link('/', 'menuaction=forum.uiforum.index') ); But almost all the 'good' php code I saw write it this way: if (!$GLOBALS['phpgw_info']['user']['admin']) { Header( 'Location: '.$GLOBALS['phpgw']-> link('/', 'menuaction=forum.uiforum.index') ); } the argument is the latter is more readable and easy to understand. But, to me, a if statement immediately followed by another statement or function call is more readable and easy to understand. It saved me from thinking what's after this statement or function call. Truly, I think keeping a stack of 'if' or 'for' in the brain is difficult for me, I tends to remove the {} and add the statement after if-clause when if statement contain only one statement. I am just thinking if my way of keeping code logic in brain is too wired. If most people truly consider the {} more easier to read/understand, I'll force myself write understandable code; if there are only very small difference in understanding (considering reading 10000 line of source, even small difficulty counts), I would like to keep my style.
Coding A Site Search...
I am starting a rather large content based site. I need a search for my site that will handle multiple words, etc. that I can have search a certain field in my db (mySQL). Are there any good places to learn how to do this so it is very efficient and speedy or are there any scripts that already do this that you could recommend with minimal modifications?
Includes Or Embedded Coding?
i am a programmer but i have never coded in PHP. I am building a PHP based site with thousands of pages through a friend who claims to be proficient in PHP. Anyway, he is suggesting that we embed PHP code within the HTML files but I have heard that it is better to keep HTML and PHP functions separate. Please advise which method is better for coding and any input you guys can give will be great. We just want to be build an efficient site that we can easily update the design and code.
Database/coding Issue?
I have users table. with usernames and info on those users. The info that i have setup for this portion is userid_2 What i have planned for this is to call up that userid_2 from everyuser in a sequence. like this: user1: userid_2 = 1 user2: userid_2 = 2 user3: userid_3 = 3 now i would like it to basically record all of these numbers.. (not add them.. subtract.. nothin like that) just record them. Then in the .php file. I want to have an if statement saying that: if userid_2 = 1 echo user1's information then display an image. if userid_2 = 2 echo user2's information then display a different image i currently don't have anything coded. on account of that i would like your guys help. b4 i totally screw it up.. then get lost. and having to rewrite it all again. (i know thats how most people start out.) but thats the miracle of these forums.
Ratings Query Coding?
I am trying to intergrate a ratings system into my project, the problem I have is I can not find an average ratings, I will try to explain clearly below with coding examples OK I have 3 recordsets 1 for restaurants with various different buildsql (primary key dine_id) I now am trying to intergrate a ratings system with this project so I have 2 additional recordsets in the code below the queries already relate to the right outlet because the code below is within my repeat region Code:
|