htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
[php] Replace/preg help :-(


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


schorhr
User

May 12, 2003, 4:40 PM

Post #1 of 5 (1453 views)
Shortcut
[php] Replace/preg help :-( Can't Post

Well, here I go--- I really suck with replace/recognition in PHP.
I have my online editor set up now, and the links will be inserted like this
a href="http://www.otherserver.com">
or
a href="http://www.thisserver.com/index.php?klicked=123">
or
a href="file.ext">


Since only index.php pages should open in the same win, I tried to write a replacement script again, but I just suck with pregs.
Files that contain thisserver or index.php?klicked=123 should have the target="_self", or no target,
and all other links should be replaced with
a <b>target="_blank"</b> href="...

Can anyone help me? thanks :-/


phoenix
Novice

May 14, 2003, 5:23 AM

Post #2 of 5 (1438 views)
Shortcut
Re: [schorhr] [php] Replace/preg help :-( [In reply to] Can't Post

Haven't you tried anything yourself yet?

On http://www.php.net/manual/en/ there are a LOT of examples for regular expressions.

For simple and fast regexps, you can also grab some from a free forum, like phpBB.

For my own system, I've made a UBB like syntax for links:
[urle=http://external.site.com]NameOfLink[/urle]
For `external' links
[urli=page_id]NameOfLink[/urli]
For `internal Links.

The regexp for the external version looks like this:

Code
$html = preg_replace("/\[urle=([^\\[]*)\\]([^\\[]*)\\[\/urle\]/e",'Utils::basicURL("$1", "$2")',$html);

(Utils::basicURL() is a function which just creates a link)

For such a default format (with the brackets) you can easily set up a regexp.

Hope this helps!


schorhr
User

May 14, 2003, 5:34 AM

Post #3 of 5 (1437 views)
Shortcut
Re: [phoenix] [php] Replace/preg help :-( [In reply to] Can't Post

Hello, thanks for your quick reply.

Surely I have tried some things myself, but I guess I am to dumb ;-)

UBB Code is not a solution here, since i want real <a href's, since static pages will be generated and opened again.

The HTMLarea editor inserts real <a href's too, and I would like to stick with that.
Sure there are some patches for htmlArea3, but I rewrote so much code I do not want to fool around with it anymore.

All i need is a replacement for anything thats not <a href=http://myserver.com/index.php?klicked=4
to <a target="_blank"
:-(

No idea?


phoenix
Novice

May 14, 2003, 6:24 AM

Post #4 of 5 (1436 views)
Shortcut
Re: [schorhr] [php] Replace/preg help :-( [In reply to] Can't Post

Ideas, lots of ideas Wink
Hmmz .. I can't tell you just like that what you need Smile

With regexps, I think it's harder to search and replace for something which doesn't contain something, then for something it does contain (if you know what I mean ..)

I guess links within your site, don't start with http://? -> just /docs/doc.html for example, without http://myserver.com in front of it.
If that's the case, you can convert the regexp from above to something that replaces all links which start with http://.


schorhr
User

May 14, 2003, 6:30 AM

Post #5 of 5 (1435 views)
Shortcut
Re: [phoenix] [php] Replace/preg help :-( [In reply to] Can't Post

Well, of course I thought of this, im not completely stupid, ha ha :-)

As you might now the htmlArea replaces most links with the whole path, especaly image tags though.
Since I am not the only one editing the pages, some still copy the whole path, so the HTTP matching would fail :-/

index.php?klicked=123
would be the term to -not- replace ..

*sigh*

 
 
 


Search for (options)