473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

replace text outside html syntax regexp php

hello regexp developers,

how can i replace text outside a html syntax by using reg exps in php?

I mean i have a text like
<h3>heading</h3>
<p>text</p>
<table>
<tr>
<td>cell1</td>
<td>cell2</td>
</tr>
</table>
or any html code.

now i want all the text outside the syntax (here: heading, text,
cell1, cell2) replaced by a special code like <img...>.

how can i code a reg exp pattern in php, that replaces each character
in the "real text" by an other piece of code, but doesnot change any
of the syntax statements?

anybodey got an idea?
help needed

andreas
Jul 16 '05 #1
1 3710
Hello again,

I did it with a for-loop:

function parse2ImageLetters($content){
global $imageLetters;
$contentArray = array();

$syntax = false;
$returnContent = "<nobr>";

for ($i=0; $i<strlen($content); $i++){
if (substr($content, $i, 1) == "<") {
$syntax = true;
$returnContent = $returnContent."</nobr>";
}
if ($syntax == true){
$returnContent = $returnContent.substr($content, $i, 1);
if (substr($content, $i, 1) == ">"){
$syntax = false;
$returnContent = $returnContent."<nobr>";
continue;
}
else {continue;}
}
if (array_key_exists(substr($content, $i, 1), $imageLetters)){
$returnContent = $returnContent.'<img class="letter"
src="'.$imageLetters[substr($content, $i, 1)].'">';
}
else{
if (substr($content, $i, 1) == " ") {$returnContent =
$returnContent."</nobr>&nbsp; <nobr>";}
else {$returnContent = $returnContent.substr($content, $i, 1);}
}

}
$returnContent = $returnContent."</nobr>";
return $returnContent;

}

cheers
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pret Orian | last post by:
I need to replace all occurancies of "is" in "This is a test (is), is, penis." with "<a href=is.htm>is</a>". The thing is, if I use a simple Replace function, the "is" in penis also gets replaced....
6
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? ...
4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
6
by: jiing24 | last post by:
I try to use regexp to replace some html tags in DOM, but the result seems some problems, ================================ <Script language="javascript" type="text/javascript"> var config =...
3
by: gregpinero | last post by:
Hi guys, What I'm trying to do is find all instances of an acronymn such as IBM on a webpage and replace it with <acronym title="International Business Machines">IBM</acronym>. However in my...
21
by: gary | last post by:
How would one make the ECMA-262 String.replace method work with a string literal? For example, if my string was "HELLO" how would I make it work in this instance. Please note my square...
6
by: alainfri | last post by:
I am not sure if this group is the right place for this question but what I need is as follows. There is a piece of html. Throughout the html there are a lot of <brtags. The task is to replace all...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.