Jump to content

String Functions In Php


Distortion

Recommended Posts

I want to make a program that does the following online.converthttp://www.hereihostmyimages.com/folder/picture001.jpgto[img ]http://www.hereihostmyimages.com/folder/picture001.jpg[/img ][img ]http://www.hereihostmyimages.com/folder/picture002.jpg[/img ][img ]http://www.hereihostmyimages.com/folder/picture003.jpg[/img ]etcetera etcetera...can I do this with php and which functions (please with a small example, im not very good with terminoligy) should i be looking at?If this is not possible or much handier in another language please tell me which one.Thanks in advance!

Link to comment
Share on other sites

You mean convert THAT when it is part of a text?You can use regular expressions to get the URL... for example (from regexlib.com):

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

Once you get the URL, you can see if it ends with ".jpg", and only then replace it with [ /img]. Keep in mind that this would be unreliable, as you can't be sure if a URL ending with ".jpg" is really an image (though in most cases, that would be true). More importantly, some PHP pages may produce images, which this approach isn't going to automatically detect.The exact functions you should look into are preg_match_all() (to get all URLs), parse_url() (to get the path URL component; especially important since a URL may have a query string and/or a fragment), pathinfo() (to get the extension), preg_replace() (to replace all appropriate matches with the appropriate BBCode).

Link to comment
Share on other sites

i'll look into those functions but I don't think I made myself clear enough.I meant the user input is something like:http://www.hereihostmyimages.com/folder/picture001.jpg and 16Then the program would output[img ]http://www.hereihostmyimages.com/folder/picture001.jpg[/img ][img ]http://www.hereihostmyimages.com/folder/picture002.jpg[/img ][img ]http://www.hereihostmyimages.com/folder/picture003.jpg[/img ]...[img ]http://www.hereihostmyimages.com/folder/picture016.jpg[/img ]so the gallery you uploaded can easily be posted on a forum or website (if you replace it with <img src="..." />)but I think I'd be better to do it in Java.

Link to comment
Share on other sites

That's exactly what this approach is for. To take a text like:

This is a sample text with this, http://www.hereihostmyimages.com/folder/picture001.jpg and more

and turn it into

This is a sample text with this, [img]http://www.hereihostmyimages.com/folder/picture001.jpg[/ img] and more

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...