Jump to content

effigy

Staff Alumni
  • Posts

    3,600
  • Joined

  • Last visited

    Never

Everything posted by effigy

  1. Word's "smart quotes" should not translate like this. Can you elaborate? All of those characters are in Windows-1252, where only "รข" carries over to Latin-1.
  2. What encoding are you working in?
  3. How do you define a number or word?
  4. <pre> <?php $fig = array ( '1,249', '33,182', '33182', '9,333', '3,981,847', '9,149', '3,294', '17,928', '1,413', '2,994' ); $fig = array_map(create_function('$num', 'return preg_replace("/\D/", "", $num);'), $fig); sort($fig); $fig = array_map(create_function('$num', 'return number_format($num);'), $fig); print_r($fig); ?> </pre>
  5. One of your <a> tags has content and there are no hrefs? How about !<a[^>]+name="[^"]+"[^>]*>.*?</a>!is?
  6. With a flexible approach to a "number" or "word": <pre> <?php $str = '>< > < >123.< > 999 < >8,88< >eight< > eig.ht < >ni.ne< > nine <'; preg_match_all('#>\s*(?:[\d,.]+(?<!\.)|[a-z.]+)\s*<#is', $str, $matches); print_r($matches); ?> </pre>
  7. What is the expected result? I get <h2>Test <p> <a href="test.php">Test2</a>. <<< is the heredoc syntax.
  8. | is a metacharacter in regex. Use \| to match a literal pipe. explode would be better in this instance.
  9. The function automatically arrays the captures; observe print_r($match);.
  10. You're matching HTML, so you're not going to see it if you print it--the browser is parsing it. <pre> <?php $str = '</td> </tr> </table>'; preg_match('%</td>\s*</tr>\s*</table>%', $str, $matches); foreach ($matches as &$match) { $match = htmlspecialchars($match); } print_r($matches); ?> </pre>
  11. At some point the . was \S to only capture non-whitespace. I can't figure out why this changed in the old posts, but that's what you're after. I've restored this and cleaned up the img addition with alternation: preg_match_all('% ( (?> ### Protocol or start. (?: (??:https?|ftp)://) | www\. ) ### Body: gobble non-space, [/url], [/img] (??!\[/(?:url|img)\])\S)+ ### Avoid ending punctuation. (?<!\s\p{P}) ) ### Not followed by an url/img end. (?!\[/(?:url|img)\]) ) %x', $str, $matches);
  12. Main Entry: hookยทer Pronunciation: \หˆhuฬ‡-kษ™r\ Function: noun Date: 1567 1 : one that hooks 2 : drink <a hooker of Scotch> 3 : prostitute
  13. Can you include a full sample of data since "Chat" and "Username" gave you trouble? Are you simply trying to remove the brackets, or add the text shown in your example as well?
  14. You need to isolate the HTML, similar to this.
  15. 1. You're only going to catch double-quoted attributes. 2. You haven't accounted for rogue white space. 3. There are various modules on CPAN for things like this; my take is below: use strict; use warnings; use XML::Twig; use Data::Dumper; my $data = <<HTML; <img src="foo" height="1" /> <img src="testing!" height="50" width="200" /> <img height="20" src="lol" /> HTML my @atts; my $twig = XML::Twig->new( twig_roots => { 'img' => sub { push @atts, $_->atts(); } } ); $twig->parse_html($data); print Data::Dumper->Dump([\@atts]);
  16. You could try a split between the two desired patterns--/(?:A|B)/--and move forward from there. If you need additional help, please provide more data.
  17. I believe this is what the manual is referring to here: There must be a better way of partitioning or analyzing your data.
  18. What about the VIN format indicates that a vehicle is "GVW < 10k lbs"?
  19. The whole pattern is stored in index 0, and the parenthetical content is stored in subsequent numbers. array_shift($matches); removed the entire pattern match.
  20. <pre> <?php $data = <<<DATA <p><em class="example"> 3.30 </em></p> DATA; preg_match('/<em class="example">\s*(\d{1,2}.\d{2})/', $data, $matches); array_shift($matches); print_r($matches); ?> </pre>
  21. <pre> <?php $string = 'My Item, N-female'; echo preg_replace('/,(?=\s+.{3})/s', '', $string); ?> </pre>
  22. <pre> <?php $tests = array( ### Pass. 'username:secret@host', 'username:secret:username@host', 'username:secret@host:000/username', 'username:secret:username@host:000/username', ### Fail. 'username:secret@host/', 'username:secret:username:etc@host', 'username:secret@host:username', 'username@host:000/username', 'username:secret:username@host:000@username', ); foreach ($tests as $test) { echo $test, ' <b>'; echo preg_match('% \A [^:@/]+:[^:@/]+(?::[^:@/]+)? @[^:@/]+ (?::\d+/.+)? \z %x', $test) ? 'Pass' : 'Fail'; echo '</b><br/>'; } ?> </pre>
×
×
  • 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.