Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Replace html tag with unicode character?

Posted on 2014-03-25
2
Medium Priority
?
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 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