golles Posted April 14, 2010 Share Posted April 14, 2010 Hey, I have a (generated) table with some numbers I'd like to change to their name (database) the number is in this format: <td>/978100/</td> or <td>/841110/841115/</td> I think it could be done with preg_match_all, but I have no clue how where to search on $search = "???"; preg_match_all($search, $table, $matches); foreach ($matches as $m){ //replace the matches with their names here } Or is this really stupid? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 It's really stupid. Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 It's really stupid. Okee, how would you do it? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Not sure. I have no idea why you're doing it that way and what you're trying to accomplish. Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 Not sure. I have no idea why you're doing it that way and what you're trying to accomplish. I want to replace the numbers with their name from the database. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Why replace them? You can't just display the names? Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 Why replace them? You can't just display the names? No the table is not generated by me. its from an application. This did allmost the trick: it only not does the ones like /841110/841115/ $search = "'/([^<]*)/'s"; result: Array ( [0] => 942480 [1] => 941750 [2] => 945955 [3] => 941230 [4] => 978100 [5] => 975600 [6] => 824110 [7] => 841290/842030 [8] => 841010 [9] => 841110/841115 ) how could the $search do them all? Quote Link to comment Share on other sites More sharing options...
cags Posted April 14, 2010 Share Posted April 14, 2010 It's because the pattern is by default greedy, there are a couple of solutions, but the simplest one is probably to just add a forward slash to the negated character class... $search = "'/([^</]*)/'s"; Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 that gave the same result this is the complete table btw <table> <tr> <td>0</td> <td>-15.75</td> <td>/942480/</td> <td>26.37</td> </tr> <tr> <td>1</td> <td>-10.567</td> <td>/941750/</td> <td>25.39</td> </tr> <tr> <td>2</td> <td>-12.267</td> <td>/945955/</td> <td>25.07</td> </tr> <tr> <td>3</td> <td>-12.233</td> <td>/941230/</td> <td>25.07</td> </tr> <tr> <td>4</td> <td>-5.683</td> <td>/978100/</td> <td>25.07</td> </tr> <tr> <td>5</td> <td>-1.183</td> <td>/975600/</td> <td>24.2</td> </tr> <tr> <td>6</td> <td>-3.667</td> <td>/824110/</td> <td>23.53</td> </tr> <tr> <td>7</td> <td>-2.15</td> <td>/841290/842030/</td> <td>22.91</td> </tr> <tr> <td>8</td> <td>-0.583</td> <td>/841010/</td> <td>22.68</td> </tr> <tr> <td>9</td> <td>-1.033</td> <td>/841110/841115/</td> <td>22.3</td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
salathe Posted April 14, 2010 Share Posted April 14, 2010 There are 10 numbers of the format that you are looking for in the HTML from the last post, your previous post showed 10 matched numbers. What's the problem? Edit: If you're looking to match 12345/67890 as two numbers, then you could do something like the following. $search = '~(?<=/)\d+(?=/)~' This uses a lookbehind* and lookahead* to search for numbers surrounded by forward slashes. * More info: lookaround Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 I would like to get those as 2 different [7] => 841290/842030 841110/841115 if those are done too, then I can continue on my own again. Quote Link to comment Share on other sites More sharing options...
golles Posted April 14, 2010 Author Share Posted April 14, 2010 Edit; I would like to get those as 2 different [7] => 841290/842030 [9] => 841110/841115 if those are done too, then I can continue on my own again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.