Jump to content

chrisran

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

chrisran's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi ! I'd like to count all occurences in "$thiscodestring" into a "dynamic?" array and print it out after the end of the loop, how do I assign the variablenames dynamically ? $query = "SELECT codes, status FROM table"; while ($row = mysql_fetch_assoc($result)) { $thiscodestring = $row[codes]; // looks like "a1 c2 d3 10 15 1 a1 a1"; $singlecodes = explode(" ", $thiscodestring); foreach($singlecodes as $thiscode) { $$thiscode[count] = $$thiscode[count] + 1; } } After all Mysql-Stuff is done I'd like to print out the counted codes, for example the code "a1" was found 100 times in all querys then $$a1[count] should be 100, c2 was found 15 times, then $$c2[count] should be 15 and so on. Question: How do I tell php to assign a "dynamic" variable with the name of the found string which was exploded (in this example a1, c2, d3... ) before ?! $$ does not seem to work. And how can I then print_r() the value if I dont know the name ? Thanks !
  2. Thanks for your reply mike, but it does not work this way: I wrote a small testprogram to check: $string = "NEWCU - Cust No 331351 0 -> 1"; $newcu = preg_match("/NEWCU - [^0-9]*([0-9]+) -> ([0-9]+)/",$string, $matches); $first = $matches[1]; $second = $matches[2]; echo "<BR><BR>NEWCU: $newcu ] $first -> $second<BR><BR>"; Result: NEWCU: 0 ] -> Any Idea ?
  3. Hi ! I've got a very long text like this: $var = "Blabla text text text [...] bla bla text text some weird text NEWCU - NEW Customer 0 -> 1 <br /> AMWHA - Some Description 0 -> 2 <br /> INST3 - Install Services 1 <br /> MORES - More Services 0 -> 1 <br /> bla bla bla text text text"; In my script I now have these keywords (NEWCU, AMWHA, MORES) set to 0 by default: $newcu = 0; $amwha = 0; $mores = 0; Now I'd like to set them to the value after the corresponding -> so for example NEWCU gets 1, AMWHA gets 2 and MORES gets 1. How do I preg_match that ? $newcu = preg_match("/NEWCU - [^] (.?) -&gt (.?)/",$var); <-- does not work. I'd like to grep on "NEWCU -" then skip everything until the -&gt and put the first digit before -&gt (here 0) into $newcu[1] and the digit after -&gt into $newcu[2].. Anyone an idea ? Thanks
×
×
  • 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.