Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/262828-regex-to-help-me-style-superscripts/
Share on other sites

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...

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.