-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
One way would be to use sscanf like: $row = '2010/06/28 22:54:59 administrator 13 -1'; $reg = sscanf($row, '%d/%d/%d %d:%d:%d %s %d %d'); And another would be to use fgetcsv and specify tab as the delimiter character. (The function is named CSV for comma-separated values, but is equally happy with tab-separated values like your file).
-
This would be much easier without regular expressions, there are tools in PHP dedicated to parsing this kind of (tab-separated value) file, or more useful (and simple) string-parsing functions to do the job manually. Do you ultimately want the array to be like that you posted (in the first post) or would you like the date and time values kept together?
-
5 random numbers that don't occur in an array
salathe replied to timvdalen's topic in PHP Coding Help
Here's an alternative idea: $pool = range(1, 45); $questions = array(5, 9, 10, 12, 33, 39); // Get a list of questions from the pool that have not already been asked $available = array_diff($pool, $questions); // Get five random questions from the list of available ones $random = array_rand(array_flip($available), 5); print_r($random); -
Just to make it clear, this code will remove more than just <br> tags from the start of a string. Given breakfast the result would be eakfast, given <b>robber</b> would result in obbe.
-
The changes that I mentioned are for your script, not the remote server.
-
You could set the user_agent INI option, or provide a stream context for SimpleXML to use. The first just dictates the default user agent to send along, the second allows far more fine-grained control of the request.
-
Awesome, now are you going to introduce yourself?
-
I don't have a Shoutcast server to try this on but the following should, theoretically, also work*. Or at least show you an alternative approach should you want to use it. echo simplexml_load_file("http://68.168.98.191:13511/admin.cgi?pass=&mode=viewxml")->SONGTITLE; * Assuming of course that the SimpleXML extension is enabled and it can talk to that URL.
-
You can't write to the interwebs.
-
Your description of the ™ not being replaced properly makes no sense, given the regex that you're using... it will never replace just an ampersand. As for having entities in the XML document, they would be fine if you used a CDATA block like <blah><![CDATA[This is my ™ text isn't it ©?!]]></blah>
-
Your regular expression is case-sensitive meaning that the lowercase letters will not match the uppercase letters which are present in the XML. Either change the regex to have uppercase SONGTITLE or use the case-insensitive pattern modifier (/.../si) to match your pattern case-insensitively. Also, why are you using antiquated methods of a) retrieving the XML and b) accessing the SONGTITLE?
-
The problem with the regex is that the * quantifier is being "greedy" and gobbling up much more than you want. You have a few options: make it ungreedy (.*?) or change the item being quantified ([^;]*). Also, why do you want to convert the entities? Can you give an example of the ATOM feed that you're working with, I have a feeling this really should be a non-issue.
-
No need for the if/else if you're using abs.
-
$diff = abs($time1 - $time2); Do you want the time difference in seconds, or some other format?
-
Do you know what you're wanting to protect against?
-
date_default_timezone_set
-
Have you had a look around the forums here? There are loads of threads asking about ignoring stuff within a tag.
-
Your regular expression should be more specific about what (where) it will match so that if the URL appears within an anchor tag, the match is not successful. This sub-forum has lots of threads trying to do precisely that.
-
PHP BBCode isnt working right
salathe replied to Dragosvr92's topic in PHPFreaks.com Website Feedback
For what it's worth, the bbcodes available here are listed in the help section (there's a link at the top of every page). Here's a direct link http://www.phpfreaks.com/forums/index.php?action=help;area=bbcode -
PHP BBCode isnt working right
salathe replied to Dragosvr92's topic in PHPFreaks.com Website Feedback
TheKiller... some text