phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Quick PHP String Question


 
Search this topic... | Search General Support... | Search Box
Register or Login to Post    Index » General Support  Previous TopicPrint TopicNext Topic
Author Message
JLA
Board Member



Joined: 30 Apr 2009

Posts: 310
Location: U.S.A


flag
PostPosted: Wed Mar 24, 2010 4:51 am 
Post subject: Quick PHP String Question

Having a brain freeze this evening on a PHP String issue

Looking to do the following

$string =" <img src="http://www.google.com/image.jpg">

Want to remove the img tag info and just leave the URL in the string. These image tags can appear in a variety of ways

$string = "<img src=http://www.googe.com/image.jpg />";

or other similar variations

Another string issue is this

Say you have this string
$string ="A test. Very nice. <img src="http://www.google.com/image.jpg">;

Say you only want to remove the extra spaces between img and src (leaving only one space) but leave the rest of the extra spaces (like after each sentence) from the string?

Thanks in advance

_________________
http://www.jlaforums.com
Back to top
JLA
Board Member



Joined: 30 Apr 2009

Posts: 310
Location: U.S.A


flag
PostPosted: Thu Mar 25, 2010 3:51 am 
Post subject: Re: Quick PHP String Question

Anyone?
_________________
http://www.jlaforums.com
Back to top
Murmur
Board Member



Joined: 20 Aug 2009

Posts: 57
Location: California


flag
PostPosted: Thu Mar 25, 2010 6:35 pm 
Post subject: Re: Quick PHP String Question

There are a ton of PHP string, file name and URL functions both standard PHP and add ons.

You might try explode with a " (quote) delimiter.

This will give you an array of all quoted sub-strings within string. You could then look for "http" in the array.

Depending on the contents of the whole element you might end up with something like this:

[0] http://www.....
[1] #004587
[2] left


============
On the second issue, you're a bit more particular and probably have to write it yourself though some stock functions will help:

subst()
rtrim(), ltrim()
strpos()
strstr()

-------------------

On a side note, the reason there are so many PHP string functions is that there is ALWAYS some particular operation you want to perform on a string for which there is no ~exact~ function. It's the nature of the beast. You just get used to using your favorite string functions and writing a littler routine to do what you want.

_________________
ComBoa - phpBB 2 Lives!
Back to top
Ptirhiik
Board Member



Joined: 19 Nov 2008

Posts: 114


flag
PostPosted: Thu Mar 25, 2010 7:50 pm 
Post subject: Re: Quick PHP String Question

Take a look at the regular expressions (google...), and preg_match_all() / preg_split() / preg_replace() functions. These are the key to isolate a <img > tag from the rest of the string, process its attributes (especially the src= one), and rebuild a string after process. WHat you are trying to do is very similar to what the bbcode parser (ie) does, or the tpl parser.
Back to top
Citrix
Board Member



Joined: 19 Feb 2012

Posts: 42



PostPosted: Wed Feb 22, 2012 7:29 pm 
Post subject: Re: Quick PHP String Question

question is too old. but if you are back here, my suggestion is to use str_replace to remove the space.

Code:
$string = str_replace("<img src", "imgsrc", $string );

will get rid of the blank space between img and src.
Back to top
JLA
Board Member



Joined: 30 Apr 2009

Posts: 310
Location: U.S.A


flag
PostPosted: Thu Feb 23, 2012 8:04 am 
Post subject: Re: Quick PHP String Question

Citrix wrote:
question is too old. but if you are back here, my suggestion is to use str_replace to remove the space.

Code:
$string = str_replace("<img src", "imgsrc", $string );

will get rid of the blank space between img and src.


Thanks - will take a look at that.

_________________
http://www.jlaforums.com
Back to top
Display posts from previous:   
Register or Login to Post    Index » General Support  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0272 seconds using 15 queries. (SQL 0.0024 Parse 0.0009 Other 0.0240)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo