Andy123
Members-
Posts
134 -
Joined
-
Last visited
Contact Methods
-
Website URL
http://codingexplained.com
Profile Information
-
Gender
Male
-
Location
Denmark
Andy123's Achievements
Newbie (1/5)
12
Reputation
-
Hello and sorry for the late reply. Thank you for your post. I couldn't get your regex to work, at least not on regexpal.com. I wrote a very simple regex myself that will match almost anything. <!DOCTYPE\s.*>
-
Hello, I have a HTML page for which I want to extract the doctype. I tried the following: $doc = new DOMDocument(); $doc->loadHTML($html); $doctype = $doc->doctype->name; However, the DOMDocument class seems to be using a default doctype if no doctype is available in the loaded HTML. I have looked around and didn't find any other options in this class. Are there any better alternatives than having to write a regular expression? My regex skills are quite rusty, so I prefer an approach that does not rely on these. Or, if anyone can help me out with the regex, that would be fine too. Thanks in advance.
-
Yes, that is the way I have always done it as well. I recently started going about it in a new way because the callback handlers you are using in your example (at least the success one) are deprecated as of jQuery 1.8 (scroll about half way down the page). Thanks again for the solution. I was going to mark the thread as solved, by the way, but I just wanted to give you another shot.
-
Hello haku, Thank you very much for your answer. It turned out that I was lucky; your solution works! I do find it a bit strange, because the HTML I get back is perfectly valid HTML. I did a console.log, and it shows the markup in the beginning of my initial post (in the error message). Before I wrote here, I did try the $.html function, but that did not work either. The encoding of my document is also correct. I am quite confused as to why I got this error in the first place, so I will paste in some more code. If you can identify the problem please let me know. Otherwise thank you very much for your help! // Inside a click event $.ajax({ type: 'POST', url: URL_SEND_MESSAGE, data: ($(form).serialize() + '&include_markup=true'), dataType: 'json' }).done(function(data, textStatus, xhr) { // Created if (xhr.status == 201) { //$(data.markup).hide().appendTo('#messageContainer').fadeIn(500); // This doesn't work $("<div/>").html(data.markup).contents().hide().appendTo('#messageContainer').fadeIn(500); // This works } }).fail(function(xhr) { /* ... */ });
-
Hey guys, I am sending an AJAX request with jQuery where I get JSON back. The JSON includes some HTML markup in UTF-8. For some reason, I get the following error when I try to create a DOM element with it (it used to work!): Uncaught Error: Syntax error, unrecognized expression: <div class="message self"> <strong>Andy123 wrote:</strong> <br /><br /> Profile link: /profile/45873/Andy123 <br /><br /> fsafawfwf222222222</div> Here is the code that triggers the error: $(data.markup).hide().appendTo('#messageContainer').fadeIn(500); If I put the same markup into a variable (or overwrite data.markup), without transferring over the network, it works as intended. Request headers: Accept: application/json, text/javascript, */*; q=0.01 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Response headers: Content-Type: application/json; charset=utf-8 I am not that good with charset and things, but to me that looks OK. Here is the JSON that is returned from the web server (PHP): {"markup":"\n\u003Cdiv class=\u0022message self\u0022\u003E\n \u003Cstrong\u003EAndy123 wrote:\u003C\/strong\u003E\n\n \u003Cbr \/\u003E\u003Cbr \/\u003E\n\n Profile link:\n\n \/profile\/45873\/Andy123\n \u003Cbr \/\u003E\u003Cbr \/\u003E\n\n fsafawfwf222222222\u003C\/div\u003E"} I suspect that it has something to do with encoding, hence why I pasted the above. Any idea what is wrong? Thanks!
-
If you want to change the available options in select #2 when you select something in select #1, then what you are looking for is Javascript and not PHP. If you want to filter from the same options in select #2 for every option in select #1 (that is, the options to be displayed in select #2 are always a subset of all possible options in select #2), then pure Javascript would do. If you just have few different options in select #2, then you could hard code this in HTML/Javascript. If you need more options and flexibility, then you could bring PHP into the picture by firing AJAX requests to your web server when a user chooses an option in select #1. You could always cache this in Javascript if you think there is a chance that people will be making many changes (although this is overkill in most situations).
-
Everything you need to know is in the manual - particularly in the "PDO" and "PDOStatement" sections. Otherwise, a quick Google search should give you what you need. I quickly found this one and it looks good. I didn't read it, though.
-
^ What he said, although I think he simply has 20 rows in his table but wants to display them all. If that is the case, simply remove the LIMIT clause.
-
As you said, polling is not a good way to go if you start to get a bit of traffic. Web sockets would be your best bet I believe. It is true that there is a challenge with the browser support, but wouldn't it be acceptable to give the user a message that their browser is updated if it doesn't support it? There are surely other methods of doing this, some of which kicken described, but many of them are quite challenging to implement. Reading your post, I have the impression that you don't want to go for something highly complicated. I'd say that web sockets is the way to go. People with old browsers can simply choose to upgrade or to not use the chat. Supporting old browser versions is something that is going away very fast, so I would just forget about it but make sure that you present the users with a user friendly message (feature checking).
-
PHP - Contact Form - Receiving blank emails
Andy123 replied to splinter_1234's topic in PHP Coding Help
What Christian F. said. I wrote some quick code below to get you started. Note that you will probably want to validate further as I am only checking to see if the submitted values are empty. But as I said, hopefully it will get you started and give you an idea on how to proceed. $Name = trim(stripslashes($_POST['Name'])); $Phone = trim(stripslashes($_POST['Phone'])); $Time = trim(stripslashes($_POST['Time'])); $errors = array(); if (empty($Name)) { $errors[] = 'You must enter a name'; } if (empty($Phone)) { $errors[] = 'You must enter a phone number'; } if (empty($Time)) { $errors[] = 'You must enter a time'; } // Done validating if (empty($errors)) { // No errors; proceed to send e-mail $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } } else { // Errors occured; loop through them and output echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } -
If I had a penny for every time someone asked about this error on this forums, I would be rich. I don't mean to be rude. The error message is actually very precise and helpful. mysql_fetch_array() is being called with a boolean value where a resource is expected. If you look at the documentation for mysql_query(), you will see that it returns FALSE on failure, which is a boolean. This value is stored in $result, which is then passed to mysql_fetch_array(). So, an error occurs with your SQL query. Perhaps you made a spelling mistake or perhaps the word "insert" is not allowed; I am actually not sure. Anyways, you can check the error like this: $result = mysql_query("SELECT id, stations, title, detail from insert") or die(mysql_error()); Also, please consider using MySQLi or PDO instead as the mysql_* extension is deprecated. I am merely name dropping here, so please take the time to read about these.
-
Hello again. Zend Framework 2.1.0 and 2.0.7 have just been released and with it came a tool! Below is a quote from the releaselog:
-
Congratulations! I have noticed a lot of great posts from you, so it seems very well deserved.
-
Thank you for the heads up. Actually, I made a silly mistake in my previous post. What I really did was to concatenate instead of add. So the line in my previous post should have been something like this instead: $user_code = (int) (rand(1,9) . ($primary_key + 164) . rand(0,9)); Sorry for the confusion.
-
Thanks for the ideas, guys. I ended up with a quite alternative approach where I use my primary key (which is obviously unique) to generate my user code. I manipulate it a bit to obscure the pattern, such that my user codes are both unique, but also less predictable. I think what I did was this (done in a stored procedure): $user_code = (rand(1,9) + ($primary_key + 164) + rand(0,9)); It may seem silly, but it makes it hard to figure out a pattern if you are not aware of the implementation. Surely this is not random, but I guess that's okay after all. Since the primary key is sequential, the middle part of the addition will always be a unique number and thus, I will not have collisions. At least that's what I think; if someone disagrees, please let me know.