Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Replace html tag with unicode character?

Posted on 2014-03-25
2
Medium Priority
?
680 Views
Last Modified: 2014-03-27
How can I replace an html tag with a unicode character.
I wasn't able to get str_replace to work.

Here are the html, phrase to replace, and the replacement string:
$html= "<p align='CENTER'>P </sup> (out) <img src='arrow.gif' alt='' /> P </sup> (in).</p>";

$text_to_replace="<img src='arrow.gif' alt=" />";

$replacement_text='&#8652'; 

Open in new window

0
Comment
Question by:code4
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39955046
<?php
$html= "<p align='CENTER'>P </sup> (out) <img src='arrow.gif' alt='' /> P </sup> (in).</p>";

$text_to_replace="<img src='arrow.gif' alt='' />";

$replacement_text=str_replace($text_to_replace,'&#8652',$html);

echo $replacement_text;

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39955840
@code4: It looks like you may be new to PHP.  There can be a lot to learn.  This article will help you get started.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Working with quotes in PHP can be a bit confusing, especially at the point where PHP and HTML and JavaScript intersect.  But it's one of the things you have to understand in order to make any progress.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

In this and your other recent question, it appears that you're working with an HTML document that was produced with Word for Windows.  That is a 20th-century fools errand.  There are many text editors that can be used to make HTML documents, or IDEs to help you create PHP scripts.  You would be better off to start with just the text and use none of the Word markup.  For example, visit this web page:
http://web.centre.edu/shiba/Chemistry%20Symbols%20in%20Word1.htm

Then copy all of the contents of the page into a text editor.  Not the "view source" but just the web rendering.  You will get something like this:
Chemistry Students:

Haven’t you wondered how to get those specialized symbols into your word-processing documents?  If you have the Lucida Sans Unicode font installed (check the font list in Word) you are in luck.

When you want to insert a symbol, click on the Insert menu and choose Symbol.  In the font box select Lucida Sans Unicode.  You will see a very rich selection of specialized characters available for use.  Here are a few that might be useful.

¿       equilibrium symbol                 code no.         21CC
¯        anion charge                                                00AF 
°         degree symbol                                             00b0
¿       degrees Celsius                                            2103
v       radical                                                          221A
¿       reaction arrow                                              2192
¿       increment                                                     2206
˜       is approximately equal to                              2248

Now, here is an even easier way to get the equilibrium symbol.  With the cursor at the insertion point where you want the symbol to appear, type 21cc, then press ALT and X simultaneously.  If you have the Lucida Sans Unicode font available, this will type the equilibrium symbol without going to the insert symbol menu.  This method will work with any of the symbols above, substituting the appropriate code before typing ALT+X.

Open in new window

Now using just the text, without the sack of gravel that Microsoft Word thinks is HTML markup, add your own HTML markup to create an HTML page that looks and says what you want.

In some versions of Word, there is an option to save a document as a PDF.  You might explore this, too.

Font information:
http://en.wikipedia.org/wiki/Lucida_Sans_Unicode

Unicode in PHP and HTML:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html

Best of luck with the project, and please post back if you still have questions about how to use PHP to modify character strings.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question