Jump to content

Mycotheologist

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Mycotheologist's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was just wondering why (.*?) works the way it does. For example, if I do preg_match('/WORD1(.*?)WORD2/'); it will match anything in between WORD1 and WORD2. I know that . is a wild card so it matches any letter. From what I've read, * matches zero or more of the preceding characters so that makes it match whole strings, rather than a single character. Its the ? that confuses me, from what I read, ? matches zero or one of the preceding characters. What purpose does that serve then? What would happen if I omitted the ?
  2. SOLVED: I solved the problem by removing the U modifier but I have no idea why it worked. I don't know what U does. I don't know what s does either but this won't work without it. Lets say I have this HTML page: <h1>BLAH BLAH BLAH</h1> sdfasdf <p> fsadfsk pspfj spdjfsdfj psadfpo </p> <p> 244524 35234546 1164146sdfgsa </p> and I need to load everything thats inside the <p> tags into an array. Heres the code I tried using: if (preg_match_all('/ <p>(.*?)<p>:/msU',$of,$matches)) { $paragraph = $matches[1][0]; but it won't work. If I echo $paragraph, it will output this: rather than just outputting the first paragraph which should be: What am I doing wrong?
  3. Ah, the answer was right under my nose the whole time. $matches[1][0] contains the value without the delimiters. Thanks a lot!
  4. I need to extract some data from text files, heres the line in the text file containing the value that I need: the value that I need is -3540.94178466. Heres the code I am using: if (preg_match_all('/SCF Done: E\(RB3LYP\) = (.*?)A.U./msU',$file_contents,$matches)) { $content = $matches[0][0]; } echo $content; When I echo the $content variable, heres what it outputs: How can I output the value itself, without the delimiters? In other words, I need to output just the value -3540.94178466, not the crap surrounding it.
×
×
  • 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.