/    Sign up×
Community /Pin to ProfileBookmark

How to replace text within variable string

Hi Guys.

Let’s say I have a string that is:

[code]
<span style=”font-family:Arial; font-size=10px; color:black”>This is the text</span>
[/code]

And I want to strip out the “font-family:Arial;” part. In other words, remove any font formatting ONLY.

The problem is it could say “Helvetica” or it could say “Arial, sans-serif”, etc.

I know I could probably find the position of font-family and then the next semicolon, but is there a way using preg-replace or something that I could say: from “font-family” to any number of characters to a semicolon? I would need this to be done with the ENTIRE string of text inputted (I am using a YUI simpleeditor and want to strip out the font-formatting.)

My regular expression writing sux.

Much appreciated.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiMay 06.2009 — My regex isn't the best either, but this should get the job done:

/font-family.+?;/i

However inline styles in general are not nice, if possible I'd move them to a stylesheet. Never used the editor you are using though so I don't know how feasible that is.
×

Success!

Help @saturnprods spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...