...

View Full Version : search and assign



extremed
12-06-2010, 01:30 PM
hi

im storing textarea values to img field of database and one row looks like


http://www.abc.com/albums/bb449/abc/abc/3.png<br />
http://www.abc.com/albums/bb449/abc/abc/4.png<br />
http://www.abc.com/albums/bb449/abc/abc/6.png<br />
http://www.abc.com/albums/bb449/abc/abc/5.png<br />
http://www.abc.com/albums/bb449/abc/abc/2.png<br />
http://www.abc.com/albums/bb449/abc/abc/cover.jpg<br />
http://www.abc.com/albums/bb449/abc/abc/1.png

is it possible to search for "cover" and assign entire line to one variable?

like
http://www.abc.com/albums/bb449/abc/abc/cover.jpg<br /> line to one variable and others to another variable?

also is it possible to sort variable according to number? so final will be like



http://www.abc.com/albums/bb449/abc/abc/cover.jpg<br />
http://www.abc.com/albums/bb449/abc/abc/1.png<br />
http://www.abc.com/albums/bb449/abc/abc/2.png<br />
http://www.abc.com/albums/bb449/abc/abc/3.png<br />
http://www.abc.com/albums/bb449/abc/abc/4.png<br />
http://www.abc.com/albums/bb449/abc/abc/5.png<br />
http://www.abc.com/albums/bb449/abc/abc/6.png<br />



Any help would be great. sorry for the language errors, hope someone can understand what i mean


Regards.

syncupsolutions
12-06-2010, 01:51 PM
Look into preg_match()

Link:
http://php.net/manual/en/function.preg-match.php

And sort()
http://us3.php.net/manual/en/function.sort.php

extremed
12-06-2010, 03:44 PM
preg_match() matches the value "cover" but i couldn't find a way to select all line which contain "cover" and assign that to a variable.

Fumigator
12-06-2010, 06:03 PM
I would assign each line to an array element and then search each element separately (with a loop). When you find a match, you can re-assign the array element, or just use it for whatever you need right then and there.

Use explode() using a delimiter of "newline" (\n) to get the thing into an array.

extremed
12-06-2010, 06:53 PM
I would assign each line to an array element and then search each element separately (with a loop). When you find a match, you can re-assign the array element, or just use it for whatever you need right then and there.

Use explode() using a delimiter of "newline" (\n) to get the thing into an array.

Thanks a lot for the idea, got it work with your idea



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum