Solved

Replace html tag with unicode character?

Posted on 2014-03-25
2
641 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 500 total points
Comment Utility
<?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 108

Expert Comment

by:Ray Paseur
Comment Utility
@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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now