-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
preg_match('#[^/]+$#', '/example999/hello.php', $match); echo $match[0]; This looks for all of the non-slash characters at the end of the string. You'll use repetition, a character class and an anchor. Another option would be to use preg_replace to remove the part that you don't need (compared with matching the part that you do need).
-
Are you using one of the JavaScript frameworks? jQuery makes working with XML fairly painless, plain-old JavaScript is more of a pain.
-
Worked for me, and didn't end up in my spam box.
-
What are you using at the moment? This should provide us with a stepping stone to help you along, rather than taking wild stabs at what you're trying to do.
-
Happy birthday pika-pika-choooooooo!
-
You could use array_filter() to remove the empty values (precisely what you use will vary depending on what you want to filter in/out). $array = array('', 'cake', 'pie', '', '', ''); $filtered = array_filter($array, 'strlen'); // $filtered is now array('cake', 'pie') (You might also like to use array_values() on the filtered array, to get back sequential 0-based keys.) As for commas within strings, for obvious reasons, that is not allowed unless the field is wrapped in double-quotes. cake,"apple, banana and pears" <--- OK, 2 fields cake,apple, banana and pears <--- SAD FACE, 3 fields
-
Does phpFreaks have any sister sites?
salathe replied to kansasakki's topic in PHPFreaks.com Website Feedback
You're also more than welcome to post lots of threads in our own JavaScript Help board. -
Not a problem, I didn't consider it rude at all. But thanks for the apology.
-
Not at all, though I do know the manual inside out. Not that particular part.
-
That is the "object operator" or, more colloquially, the "arrow operator". Its token name when PHP parses your code into pieces is T_OBJECT_OPERATOR.
-
Absolutely, just without the uncertainty.
-
That could be rewritten simply as $searchFor = array('REF*19**', 'REF*GG*'); $lineArray = array('REF*19**PHILADELPHIA 02', 'REF*GG*CUT PILE'); $newEdiArray = str_replace($searchFor, '', $lineArray);
-
The => operator is, perhaps confusingly, called a "double arrow" (the token name that PHP sees is T_DOUBLE_ARROW). It is used in two places, neither being anything directly related to objects or OOP. [*]When assigning keys to be associated with array values $fruits = array('a' => 'apple', 'b' => 'banana'); [*]When retrieving the key in a foreach loop foreach ($fruits as $key => $value) {
-
Okay, well that didn't help at all. First you're changing the scope of the question entirely (by dealing with HTML documents) and secondly, no new information regarding what you've been trying, how they've been failing, etc.. How about showing us where you're at at the moment and how that does not do what you want it to do?
-
So you just want to match any 0x???????? (where ? is a hexadecimal digit) numbers that aren't within comment lines?
-
Sometimes I just have to let the little helpful badger type something, else he gets upset!
-
Your regex /^server/\./port\s=\s/ is broken, please turn on displaying of errors (ini_set('display_errors', true)) and allow all errors to be reported (error_reporting(-1)) and you will see that PHP tells you that the regex is broken with the message Warning: preg_match() [function.preg-match]: Unknown modifier '\' in …. I have absolutely no idea why you have the forward slashes around the dot part of the regex, but they are not needed so remove them: /^server\.port\s=\s/ Secondly, you want to match the port number but nowhere in the regex is looking for any sort of number at all! Specify that a) you want to find a port number, and b) that you want to capture it separately for use later. /^server\.port\s=\s(\d+)/ Thirdly, you ask to match only at the start of the subject string (with ^) where instead you want to match at the start of a line. To allow the caret (^) to match the start of a line, you need to set the "multiline" pattern modifier (docs): /^server\.port\s=\s(\d+)/m With the amended regex, you will now be able to use $matches[1] to get the port number.
-
RegEx to determine if a word is inside anchor tags
salathe replied to brianlange's topic in Regex Help
Unless you're reading in a plain text file, there will always be HTML tags around your chosen word; unless you really mean something much more specific like literally, only, around the word itself? Could you elaborate a little more on precisely what you want to accept as matching and what you want to disallow from matching? Also, if you've made a start on matching the word but cannot quite adapt that to looking for tags, post up any regex that you have at the moment for us to help you to adapt it. -
Just in case things aren't clear, lets go over the fixes offered. Fixing the "range out of order in character class" error caused by [a-zA-Z0-9._- ] (since that is the only character class in the regex!). Ranges are things like a-z, which covers the range of characters starting at a and ending at z (so, the alphabet), and 0-9. Breaking apart your character class, there are in fact four ranges specified: 1. a-z, 2. A-Z, 3. 0-9 and 4. _-<space> where <space> is a literal space character. It is this final, accidental, range which causes the problem. It is worth going on a little bit of a tangent here and mentioning that the start/end characters for ranges must be in order, meaning that z-a is not valid. Take a look at a table of ASCII characters and note that the ASCII number of the range characters must be from low to high. Taking the values for underscore and space, 95 and 32 respectively, we can see that the order is incorrect just like z-a. If you were to have written the character class as [a-zA-Z0-9. -_], there would have been no error message because it is perfectly okay to have a range of "space to underscore"... however (again, take a look at the ASCII table) that would allow matching of any character between space and underscore, things like !, %, =, and @! Negating the character class First, that is the technical term for [^…]. That changed the regex from asking, "can I match a sequence of one or more characters from the character class, anywhere within the subject string?" to "can I match a sequence of one or more characters that are not from the character class, anywhere in the subject string?" The idea works, but it is also possible to make life simpler. Currently you have [^a-zA-Z0-9._ -]+, however all that you really care about is finding any occurrence of an invalid character. If we can match one bad character, and exit from trying to match anything more at that point, then that makes life easier on the regex engine doing all of the hard work. So, instead of asking for "one or more", we can just ask for "one"; this is done simply by removing the + repetition quantifier (i.e. we don't care about matching the character class more than once). This is a very minor point, but always worth keeping in mind as no-one likes doing more work than is really necessary, computers included! P.S. Good luck with the rest of the system.
-
Some folks prefer the "alternative" syntax when mixing HTML or other blocks of output with basic PHP, especially when mixing different types of control blocks (loops, conditions, etc.) where the closing statement (endwhile, endif, etc.) is much clearer than a random curly brace . Outside of that, it's not very common at all to it.
-
Which metals? Have you contacted, or looked at data offered from, any of the exchanges?
-
The xmlNode function being used is not part of PHP by default. Somewhere else in your script it will have been defined (function xmlNode(...)), without seeing that definition we cannot do anything other than guess what it is and how it works. It looks like the function might take a node name and a value, and return those as an XML element. For example, xmlNode("cake", "carrot") might return <cake>carrot</cake>.