Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. preg_match('~^"(?:[^"]|"")*"~',$string,$match); edited to add a ^ to the beginning of the pattern; didn't notice you wanted it to only match if its at the beginning.
  2. can you be more specific as to what's not working? I don't know if you were just posting as an example or how you actually have it, but preg_match_all assigns the results to the specified 3rd argument like so: preg_match_all($pattern, $content, $result); print_r($result); with preg_replace, the results must be assigned how things are usually assigned, like so: $result = preg_replace($pattern,$replacement, $content); tbh I have no idea why preg_match(_all) does not do it the same way, but..yeah...anyways, if that's not the issue, then post example content.
  3. your pattern doesn't match the space before the (..) though, so it will be added to the end of the sentence.
  4. ooh good call on the no empty flag.
  5. $test ="this is sentence number one (1) here is sentence number two (2)"; $sentences = preg_split("~\s?\(\d+\)\s?~",$test);
  6. okay, so you understand, take that test.html you made and rename it to test.php. You will see that the it works. But having a php file that is pulling it from the database probably displays it differently, maybe with some \n's or who knows what. depends on your code. I'm pretty sure that your pattern is breaking because your php is generating content that's not the same as your test.html. At the very least, try using an s modifier like so: preg_match_all("/<div id=\"divtag1\">.+<\/div>/s", $page, $matches, PREG_SET_ORDER); But also, you're saying that you made a "test" html file well patterns work differently within different contexts. For instance, that .+ will work for you if you only have 1 closing div tag in your test but you're now talking about your php file outputting content, so if it's outputting a bunch of other closing divs on the whole page, you regex is not going to act as intended, because .+ is greedy and will match up to the very last div. At the very least, you should add a ? after the + to make it non-greedy. But anyways, I can't really do anything more than guess seeing as how you aren't showing the content for which you're trying to regex from.
  7. thread closed. Read the numerous stickies all over the place.
  8. php executes its code server side and sends the results to the browser or whatever else is requesting it. It doesn't matter what the extension is. file_get_contents grabs the rendered output, exactly as if you were to rightclick > view source through your browser. Think the first thing I would check is make sure index.php has the same stuff you're trying to match.
  9. then post an example of the content
  10. if you use single quotes around things, everything in-between is interpreted literally. Like variables and escaped characters such as that linebreak character. Use double quotes for them to actually be parsed.
  11. well I do notice the string you provided for the pattern says profie.php perhaps you meant to have profile.php ?
  12. using in_array to see if it's even in the array and then reducing the foreach loop by yanking all the keys of the matches and just looping through those instead of whole array.... $file = file('test.txt'); // your file name inside quotes $hash = 'a8sdfjujakl29d8ajsdf' . "\n"; if (in_array($hash, $file)) $hashLine = array_keys($file,$hash); foreach ($hashLine as $key) $values[] = trim($file[$key+1]); echo "<pre>";print_r($values);
  13. you can have variable length in lookaheads but not lookbehinds.
  14. preg_match('~<td><a href="profie.php?username=([^"]*)">(.*?)</a></td>~',$buf, $matches); echo "<pre>"; print_r($matches); // to see the array structure of your returns
  15. google positive and negative lookaheads and lookbehinds.
  16. If you are sure that will be the format 100% of the time... $number="(381) 323-4567"; $number = preg_replace('~\((\d{3})\) (\d{3})-(\d{4})~','$1 $2 $3',$number); If you are not sure that will be the format 100% of the time... $number="(381) 323-4567"; $number = preg_replace('~[-(). ]~','',$number); $number = substr($number,0,3) . " " . substr($number,3,3) . " " . substr($number,-4);
  17. okay then can you give an example of the whole page that you're trying to pull the info from?
  18. try adding .*?</div> to the end of your pattern.
  19. Yes, that certain someone found the problem because they looked at your code. Had you posted your code here, someone probably could have helped you just the same. I'm sorry I couldn't give you a more constructive answer, but that's your fault for expecting an answer to why your code isn't working, without posting your code. That's like going up to a mechanic and asking what's wrong with your car, but you left your car at home. It's common sense.
  20. You can start off by showing your code because we aren't psychic.
  21. $file = file_get_contents("./test2.txt"); preg_match_all('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/is',$file,$matches); echo "<pre>";print_r($matches); if ($matches[0]) { echo "no emails in file"; } else { foreach ($matches[0] as $email) { echo "$email<br/>"; } }
  22. "level system" is pretty ambiguous... care to be more specific?
  23. Assumes userfield="height1" is a unique attribute to the span inside the div you want to match, that will be in all the spans inside those divs. preg_match_all('~<div.+?"td user_ref"[^>]*>.+?<span.+?userfield="height1"[^>]*>(.*?)</span>~is',$html,$height); print_r($height[1]);
  24. How about reading the manual for what the imagestring arguments are.
×
×
  • 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.