peppericious Posted May 20, 2012 Share Posted May 20, 2012 I want to mark text snippets with superscript numbering. The numbering will refer the reader to corresponding footnotes later. In my text, I want to quickly enter the superscripts like this: *1* *2* *3* *4* ... *9* *10* *11* .. etc. I want to wrap the superscripts in a span tag to style them. So, my question: how to I replace the opening and closing asterisks so that I'll end up with: <span class='superscript'>1</span> <span class='superscript'>2</span> <span class='superscript'>3</span> <span class='superscript'>9</span> ... <span class='superscript'>10</span> <span class='superscript'>11</span> Given the content I'm working on, it is highly unlikely that the superscript number will ever be longer than 2 digits. Thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 20, 2012 Share Posted May 20, 2012 To start with, /\*(\d+)\*/ Quote Link to comment Share on other sites More sharing options...
peppericious Posted May 20, 2012 Author Share Posted May 20, 2012 Perfect. Thank you very much! It's *really* time for me to start learning some of this regex stuff. Quote Link to comment Share on other sites More sharing options...
peppericious Posted May 20, 2012 Author Share Posted May 20, 2012 To start with, /\*(\d+)\*/ I spoke too soon... I can't get this to work. What you have given me is replacement pattern I should use in conjunction with the preg_replace function, is that right? I am finding it difficult to specify the original pattern... Quote Link to comment Share on other sites More sharing options...
peppericious Posted May 20, 2012 Author Share Posted May 20, 2012 Got it!... <html> <head> <style type='text/css'> .ss { color:red; } </style> </head> <body> <?php // style superscripts $str = "Testing*1* one two three"; $tosearchfor = "/\*(\d+)\*/"; $toreplacewith = "<span class='ss'>$1</span>"; echo preg_replace($tosearchfor, $toreplacewith, $str); ?> </body> </html> 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.