Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by AyKay47

  1. perhaps you can explain why so I can learn from it. I do not perform regexp on text files ever really, I'm assuming that a PHP solution would normally be best.
  2. yes you can, if you notice there is a "show unread posts since last visit" link at the top left of the page (next to your profile picture). This shows all unread posts of all of the sub forums, this can be sorted by reply.
  3. yeah, you still will only need one regex for this: $pattern = "~^[a-z]{2,12}(\s[a-z]{2,20})?$~i"; this pattern will attempt to match a first and last name first, if it doesn't find one, it will match the first name (with trailing spaces disallowed)
  4. and you don't overwrite the value of $conn1 in your script at all? maybe if you show the relevant code from where you set $conn1 to where the error occurs that will help.
  5. to answer the edit to your thread that you have made, only one regex is needed for this, not sure why you have two. Your regex is a little sloppy, and will allow a name like "Green Trancer" so I will clean it up. The multiple character classes are not needed, as you can simply append the "case insensitive" modifier to the pattern. Also, you should have a specific range on the character class, there must be a min and max amount of characters allowed, correct? $str = "Green Trancer"; $pattern = "~^[a-z]{2,12}\s[a-z]{2,20}$~i"; preg_match($pattern,$str,$ms); print_r($ms); This regex has the following rules: 1. the first name must be [a-zA-Z] and between 2 and 12 characters (taking into account weird 2 letter first names) 2. there must be a space, and only one space following the first name. 3. the last name can only be [a-zA-Z] and between 2 and 20 characters. (again, taking into consideration weird last names.) 4. The full name must be the only part of the subject, if there is any other text in the string, the regex will fail as expected.
  6. in these regex examples, the + and * are repetition operators, the + after the character class [a-z] tells the regex engine to search for the character class at least one time (greedy). The * after the character class [a-z] tells the engine to search for the class 0 or more times (greedy), in essence making the character class optional (however, since the * is greedy, it will attempt to find as many character matches as possible). The $ is an end of string anchor, a zero-width positional character that will match the void space after the last character in a string.
  7. With a little math, sure. function returnPercent($num1,$total) { return round($num / $total * 100) . "%"; }
  8. Whatever credentials you are using, they aren't correct. You can look in the servers php.ini file for the credentials (although they might not be there). But the user and pass will be what you set them to, if you can't remember them, contact your provider.
  9. whatever $conn1 holds in your script you gave us doesn't hold a valid resource. Thus the error.
  10. do you care whether or not the regex omits spaces?
  11. $_SERVER['PHP_SELF'] has nothing to do with the referring page at all, it holds the file name of the executing script, relative to the doc root. Keep in mind, the referrer can be tampered with.
  12. have you changed your mysql_connect credentials to relate to the new server?
  13. edit to the above post, the last regex is not meant to be there, my mistake...
  14. this: $str = "p > a{ color: red; }"; $pattern = '~([.#:>\-_,a-z0-9 ]+)({)~i'; $replacement = '<span style="color:#333;font-weight:bold;">$1</span>$2'; echo preg_replace($pattern,$replacement,$str); works for me (tweaked it a tad). Edit: edited for &gt (you can also use the hex value is you wish, which would be \x{003E}, as playful suggested, but make sure the u modifier is appended to the regex) $pattern = '~([.#:>\-_,a-z0-9& ]+)({)~i';
  15. it looks to be working nicely! If I think of any improvements to add to the regex I will post them on this thread.
  16. let me know if this has worked out for you.
  17. so you want the regex to grab 2 separate sets of characters, a set with the alphanumeric characters between the quotes, and a set of the non-alphanumeric characters between the quotes, correct?
  18. im curious to see what the regex you are using looks like?
  19. you're not giving me enough to go on here, tell me the exact specifications of what table(s) you want to grab, and if you want to grab more than one table.
  20. oh okay, of course it's possible: $str = "<table class='price' id='comp' style='clear:both;display:none'>this is a test</table>"; $pattern = '~<table[^>]*>([^<]*)</table>~'; preg_match($pattern,$str,$matches); print_r($matches); $matches[0] will contain the entire matched string and $matches[1] will contain the text between <table</table>
  21. if you want to match that exact format, you can use this. $str = "<table class='price' id='comp' style='clear:both;display:none'>"; $pattern = '~<table class=("|\')price("|\') id=("|\')comp("|\') style=("|\')clear:both;display:none("|\')>~'; preg_match($pattern,$str,$matches); print_r($matches); where $matches[0] will contain the matched string. if you want this regex to match a dynamic beginning <table> element, I will have to revise it.
  22. Well I wasn't going to assume that with a Regex. Why not? It is simply a function like any other. False is false, it doesn't matter where it came from. Because when it comes to things like 0 and FALSE and == and === things are not always as them seem. If I trusted the outcome based on my knowledge I obviously wouldn't post here. When I post here it is because I either 1.) Don't know how to do something, 2.) Don't trust my knowledge, or 3.) Want other people's opinions on choosing a better approach. I'm a newbie - and not an expert like you all - so I require more hand-holding. Debbie Remember, this is a help forum, we are here to help you along the way, not do the work for you (not saying that you are asking someone to do the work for you in this case). We expect that you (a user of the forums) will give your best effort to find a solution to the problem before asking for help on this forum. Now this particular question you could have answered yourself by simply running a few test scripts and analyzing the results, as Pika said. Don't smack the hand that tries to hold yours.
  23. 1. well, this regex took a little bit of trial and error. I know that a word boundary (\b), if placed to the left of an alphanumeric character, will only match an alphanumeric character if a non-alphanumeric character is to the immediate left of it. same goes for placing a boundary on the right of an alpha-numeric character, it will only match if a non-alphanumeric character immediately follows an alphanumeric character. Now since the text that you want to replace will always be in between either a space, curly bracket, colon, or semi-colon, these are all non-alphanumeric characters, I knew that word boundaries would match only those cases. I had to add [^.] in the beginning of the regex so it would not match a.link, since the word boundary would see the the non-alphanumeric character period (.) followed by an alphanumeric character (l) and would match that case, which we do not want. 2. I believe the [^.] is grabbing the tab before the CSS string.. what you can do is remeber this character, and back reference it back into the replacement string. $str = "a.link:hover{ text-decoration: underline; color: #222; }"; $pattern = '~([^.,])\b([a-zA-Z-]+?)\b(~'; $replacement = '$1<span style="color:#0000ff;font-weight:bold;">$2</span>$3'; echo preg_replace($pattern,$replacement,$str); this should add the tab back into the string. Edit: Thinking about this, I have made the regex a little more robust to also allow commas, for multiple element CSS.. $str = "a.link:hover, a.link:active{ text-decoration: underline; color: #222; }"; $pattern = '~([^.,])\b([a-zA-Z-]+?)\b(~'; $replacement = '$1<span style="color:#0000ff;font-weight:bold;">$2</span>$3'; echo preg_replace($pattern,$replacement,$str);
  24. depends, do you want the float to round up if it is .5 or greater? e.g. a divided value of 3.5 would return 4.
  25. here is what I have come up with for you. $str = "cough|exhale abruptly, as when one has a chest cold or congestion; \"The smoker coughs all day\"\n hack|cough spasmodically; \"The patient with emphysema is hacking all day\"\n expectorate|discharge (phlegm or sputum) from the lungs and out of the mouth\n snort|make a snorting sound by exhaling hard; \"The critic snorted contemptuously\"\n wheeze|breathe with difficulty\n"; $pattern = '~;(.+?)(\r|\n)~'; $replacement = '$2'; echo preg_replace($pattern,$replacement,$str); output. cough|exhale abruptly, as when one has a chest cold or congestion hack|cough spasmodically expectorate|discharge (phlegm or sputum) from the lungs and out of the mouth snort|make a snorting sound by exhaling hard wheeze|breathe with difficulty some of the regex relies on the control/format of your txt file
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.