Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-22-2004, 02:25 PM
|
#1
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Rep:
|
[php]Reading url [img] and [/img]
Hello
Im writing a script language that looks like bbcode, so far, i did evrything with str_replace.
But i also need pictures, so i have to read text between [img ] and [/img ](minus those spaces).
So how do i do that?I hope sb can help me.
thanx Hylke
|
|
|
|
08-22-2004, 02:50 PM
|
#2
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
Try preg_replace() like :
PHP Code:
$text = "Im writing a script language that looks like
bbcode [ img]http://image.com/smiley.png[ /img] so far,
i did evrything with";
$img = preg_replace("/.*\\[img\\](.*)\\[\\/img\\].*/", "\\\\1", $text);
echo $img;
edit : hard to figure out how to display img markup properly 
Last edited by Cedrik; 08-22-2004 at 02:56 PM.
|
|
|
|
08-22-2004, 03:25 PM
|
#3
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
If you're not used to regular expression you can do something like this (not very clean solution though, i'd prefer reg expressions):
Code:
$newstring = strtr ( $inputstring, array("[ img ]" => "", "[ /img ]" => "") )
This will replace in inputstring the [ img ] and [ /img ] with an empty string (= remove it).
Like this you have in newstring just the content between the tags.
But nevertheless, if you really want to make it in a clean and much more elegant way, i suggest you to learn regular expressions (sooner or later you won't get around them anyway).
Last edited by Charalambos; 08-22-2004 at 03:27 PM.
|
|
|
|
08-23-2004, 03:40 AM
|
#4
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Original Poster
Rep:
|
Thanks you all
Hylke
EDIT:
The code:
PHP Code:
<?php
$text = "Im writing a script language that looks like
bbcode [ img]http://image.com/smiley.png[ /img] so far,
i did evrything with";
$img = preg_replace("/.*\[img\](.*)\[\/img\].*/", "\\1", $text);
echo $img;
?>
Gives me the following output:
Quote:
|
Im writing a script language that looks like bbcode [ img]http://image.com/smiley.png[ /img] so far, i did evrything with
|
So i gues there's something wrong with the code.
Last edited by hylke; 08-23-2004 at 03:48 AM.
|
|
|
|
08-23-2004, 03:52 AM
|
#5
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
You have to remove the spaces in the [ img] and [ /img] tag.
edit: (because the regular expression matches the tags without spaces).
|
|
|
|
08-23-2004, 05:09 AM
|
#6
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Original Poster
Rep:
|
I've done that, but it simply removes those img tags, but i want only the url, and not all the other text.
Hylke
|
|
|
|
08-23-2004, 05:11 AM
|
#7
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
Thats exactly what it's supposed to.
It you want more to be removed, add the desired match to the regular expression.
|
|
|
|
08-23-2004, 05:27 AM
|
#8
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Original Poster
Rep:
|
How do i do that?
Because i dont understand how to do that with all those /,*/ and other signs.
Thanx Hylke
|
|
|
|
08-23-2004, 06:37 AM
|
#9
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
Thats what i told you, you should learn how regular expressions work and how their syntax is in order to get that one straight. Thats why i showed you the version above avoiding regular expressions (in case you don't want to learn).
|
|
|
|
08-23-2004, 06:40 AM
|
#10
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
And btw, you just have to take Cedrik's example and substitute the string that is replaces those tags, and you have what you're looking for (if not, i didn't understand what you were looking for, and you have to tell me again).
|
|
|
|
08-23-2004, 06:51 AM
|
#11
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Original Poster
Rep:
|
Sorry, but what does substitute mean?
|
|
|
|
08-23-2004, 06:54 AM
|
#12
|
|
Member
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149
Rep:
|
Substitute = replace.
This means you just have to put the desired string instead of the one in the example.
|
|
|
|
08-23-2004, 12:38 PM
|
#13
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
In my system the regex give only the url, nothing more... try again (replace [image] by [img])
$text = "some words before [image]http://site.com/image.png[/image] some words after...";
$url = preg_replace("/.*\[image\](.*)\[\/image\].*/", "\\1", $text);
$echo $url;
Last edited by Cedrik; 08-23-2004 at 12:39 PM.
|
|
|
|
08-23-2004, 01:58 PM
|
#14
|
|
Member
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329
Original Poster
Rep:
|
Thanx
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Bootdisk.img
|
mithu_sree |
Linux From Scratch |
2 |
05-13-2005 03:50 AM |
|
What's an initrd.img?
|
hotel-lima |
Linux - Newbie |
2 |
06-11-2004 05:50 PM |
|
.img?
|
dwessell |
Linux - Software |
3 |
05-21-2004 09:06 AM |
|
.img burner or way to boot from a .img
|
American Psycho |
Linux - Software |
4 |
03-24-2004 06:40 AM |
|
img
|
onetimewhiner |
Linux - Software |
1 |
09-07-2001 03:42 AM |
All times are GMT -5. The time now is 11:00 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|