Re: [PHP] a little trickery

2012-09-09 Thread David McGlone
On Sunday, September 09, 2012 03:02:17 PM Stuart Dallas wrote:
> On 9 Sep 2012, at 04:19, David McGlone  wrote:
> > On Saturday, September 08, 2012 03:49:27 PM you wrote:
> >> On 8 Sep 2012, at 15:35, David McGlone  wrote:
> >>> I have a function that reads a directory and gets all the file names of
> >>> images, and I am wondering if it's possible to concatinate this function
> >>> withint an image tag. Here's an example I tried.
> >>> 
> >>> function pictures() {
> >>> 
> >>>   $dir = 'images/property_pics/';
> >>>   $file = array();
> >>>   
> >>> if(is_dir($dir)){
> >>>   
> >>>   if($open = opendir($dir)){
> >>>   
> >>> while (($file = readdir($open)) !== false && $file !== ".") {
> >>>   
> >>>   $names = substr($file, 9, 20);
> >>>   echo $names;
> >>>   
> >>>   }
> >>>   
> >>>   }
> >>>   
> >>> closedir($handle);
> >>>   
> >>>   }
> >>> 
> >>> }
> >>> 
> >>> $rs = $pager->paginate();
> >>> 
> >>> if(!$rs) die(mysql_error());
> >>> while($row = mysql_fetch_assoc($rs)) {
> >>> 
> >>>   echo "";
> >>>   echo "";
> >>>   echo 
> >>> 
> >>> What I am trying to do is get the last part of an image name, because I
> >>> know the $MSL_No is always a 9 character name which matches the image
> >>> name in but in the database, the last bit of characters are not there so
> >>> I'm trying to take the last characters of the image name and concatinate
> >>> them to each image name..
> >>> 
> >>> Wow this is harder to explain that I thought. Here's an example
> >>> 
> >>> In the DB I have a row MSL_No and the contents is: 123456789
> >>> 
> >>> In my images folder I have an image named 123456789_R13_1.jpg
> >>> 
> >>> My goal: get the MSL_No out of the DB and concatenate anything after it
> > 
> > so
> > 
> >>> I would end up with the whole image name..
> >>> 
> >>> I hope this all made sense. :-/
> >> 
> >> Is there just one image in the folder that starts with the 9 digit
> >> number?
> >> In that case it's dead simple (untested code):
> >> 
> >>  >> 
> >>  function completeImageFilename($prefix)
> >>  {
> >>  
> >>$matches = glob('images/property_pics/'.$prefix.'*');
> >>return $matches[0];
> >>  
> >>  }
> >>  
> >>  echo '';
> >> 
> >> ?>
> >> 
> >> If you need to extract more than one image filename you should be able to
> >> modify that pretty easily.
> > 
> > YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the
> > world did you get $prefix to contain the image name without first
> > assigning it to $prefix? I understand the rest, but. Holy smokes,
> > that's blown my mind. :-/

> I really can't tell whether you're being sarcastic, so I'll assume you're
> not.

Sorry about that. No sarcasm here. I was so taken aback on how different your 
code was.  I thought I was never going to understand the way you did it vs the 
way I tried. Sorry about that.
> 
> Read about function arguments: http://php.net/functions.arguments

Thanks. I'll go read it now. :-)

-- 
Regards
David M.

Re: [PHP] a little trickery

2012-09-09 Thread Stuart Dallas
On 9 Sep 2012, at 04:19, David McGlone  wrote:

> On Saturday, September 08, 2012 03:49:27 PM you wrote:
>> On 8 Sep 2012, at 15:35, David McGlone  wrote:
>>> I have a function that reads a directory and gets all the file names of
>>> images, and I am wondering if it's possible to concatinate this function
>>> withint an image tag. Here's an example I tried.
>>> 
>>> function pictures() {
>>> 
>>>   $dir = 'images/property_pics/';
>>>   $file = array();
>>> 
>>> if(is_dir($dir)){
>>> 
>>> if($open = opendir($dir)){
>>> 
>>>   while (($file = readdir($open)) !== false && $file !== ".") {
>>> 
>>> $names = substr($file, 9, 20);
>>> echo $names;
>>> 
>>> }
>>> 
>>> }
>>> 
>>> closedir($handle);
>>> 
>>>   }
>>> 
>>> }
>>> 
>>> $rs = $pager->paginate();
>>> 
>>> if(!$rs) die(mysql_error());
>>> while($row = mysql_fetch_assoc($rs)) {
>>> 
>>>   echo "";
>>>   echo "";
>>>   echo 
>>> 
>>> What I am trying to do is get the last part of an image name, because I
>>> know the $MSL_No is always a 9 character name which matches the image
>>> name in but in the database, the last bit of characters are not there so
>>> I'm trying to take the last characters of the image name and concatinate
>>> them to each image name..
>>> 
>>> Wow this is harder to explain that I thought. Here's an example
>>> 
>>> In the DB I have a row MSL_No and the contents is: 123456789
>>> 
>>> In my images folder I have an image named 123456789_R13_1.jpg
>>> 
>>> My goal: get the MSL_No out of the DB and concatenate anything after it 
> so
>>> I would end up with the whole image name..
>>> 
>>> I hope this all made sense. :-/
>> 
>> Is there just one image in the folder that starts with the 9 digit number?
>> In that case it's dead simple (untested code):
>> 
>> >  function completeImageFilename($prefix)
>>  {
>>$matches = glob('images/property_pics/'.$prefix.'*');
>>return $matches[0];
>>  }
>> 
>>  echo '';
>> ?>
>> 
>> If you need to extract more than one image filename you should be able to
>> modify that pretty easily.
> 
> YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world 
> did you get $prefix to contain the image name without first assigning it to 
> $prefix? I understand the rest, but. Holy smokes, that's blown my mind. 
> :-/

I really can't tell whether you're being sarcastic, so I'll assume you're not.

Read about function arguments: http://php.net/functions.arguments

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] a little trickery

2012-09-08 Thread David McGlone
On Saturday, September 08, 2012 11:19:29 PM David McGlone wrote:
> On Saturday, September 08, 2012 03:49:27 PM you wrote:
> >  > 
> >   function completeImageFilename($prefix)
> >   {
> >   
> > $matches = glob('images/property_pics/'.$prefix.'*');
> > return $matches[0];
> >   
> >   }
> >   
> >   echo '';
> > 
> > ?>
> > 
> > If you need to extract more than one image filename you should be able to
> > modify that pretty easily.
> 
> YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world
> did you get $prefix to contain the image name without first assigning it to
> $prefix? I understand the rest, but. Holy smokes, that's blown my mind.

I read about glob() on php.net before I replied, but I believe now it's 
registering. From what I understand glob works just like opendir() but does 
everything all in just 1 function. so in your code I realize you passed the 
variable $prefix into glob, along with the path to the files. This put the path 
images/property_pics/ and each image name from glob into $prefix you then 
assigne the value of $glob to $matches. Sound about right? :-)
 
-- 
Regards
David M.

Re: [PHP] a little trickery

2012-09-08 Thread David McGlone
On Saturday, September 08, 2012 03:49:27 PM you wrote:
> On 8 Sep 2012, at 15:35, David McGlone  wrote:
> > I have a function that reads a directory and gets all the file names of
> > images, and I am wondering if it's possible to concatinate this function
> > withint an image tag. Here's an example I tried.
> > 
> > function pictures() {
> > 
> >$dir = 'images/property_pics/';
> >$file = array();
> >
> >  if(is_dir($dir)){
> > 
> > if($open = opendir($dir)){
> > 
> >   while (($file = readdir($open)) !== false && $file !== ".") {
> > 
> > $names = substr($file, 9, 20);
> > echo $names;
> > 
> > }
> > 
> > }
> > 
> >  closedir($handle);
> >
> >}
> > 
> > }
> > 
> > $rs = $pager->paginate();
> > 
> >  if(!$rs) die(mysql_error());
> >  while($row = mysql_fetch_assoc($rs)) {
> >  
> >echo "";
> >echo "";
> >echo 
> > 
> > What I am trying to do is get the last part of an image name, because I
> > know the $MSL_No is always a 9 character name which matches the image
> > name in but in the database, the last bit of characters are not there so
> > I'm trying to take the last characters of the image name and concatinate
> > them to each image name..
> > 
> > Wow this is harder to explain that I thought. Here's an example
> > 
> > In the DB I have a row MSL_No and the contents is: 123456789
> > 
> > In my images folder I have an image named 123456789_R13_1.jpg
> > 
> > My goal: get the MSL_No out of the DB and concatenate anything after it 
so
> > I would end up with the whole image name..
> > 
> > I hope this all made sense. :-/
> 
> Is there just one image in the folder that starts with the 9 digit number?
> In that case it's dead simple (untested code):
> 
>function completeImageFilename($prefix)
>   {
> $matches = glob('images/property_pics/'.$prefix.'*');
> return $matches[0];
>   }
> 
>   echo '';
> ?>
> 
> If you need to extract more than one image filename you should be able to
> modify that pretty easily.

YEOW! LOL I looked at this and I'm very stumped on 1 thing. How in the world 
did you get $prefix to contain the image name without first assigning it to 
$prefix? I understand the rest, but. Holy smokes, that's blown my mind. :-/

-- 
Regards
David M.

Re: [PHP] a little trickery

2012-09-08 Thread Daniel Brown
On Sat, Sep 8, 2012 at 10:49 AM, Stuart Dallas  wrote:
>
> Is there just one image in the folder that starts with the 9 digit number? In 
> that case it's dead simple (untested code):
>
>function completeImageFilename($prefix)
>   {
> $matches = glob('images/property_pics/'.$prefix.'*');
> return $matches[0];
>   }
>
>   echo '';
> ?>

Stuart is, as usual, right on.  Rather than do the filesystem
handlers and loops, you should definitely consider glob().  Not only
is it quicker, cleaner, and easier to use, but it's far less
resource-intensive than your current implementation.

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] a little trickery

2012-09-08 Thread Stuart Dallas
On 8 Sep 2012, at 15:35, David McGlone  wrote:

> I have a function that reads a directory and gets all the file names of 
> images, 
> and I am wondering if it's possible to concatinate this function withint an 
> image tag. Here's an example I tried.
> 
> function pictures() {
> 
>$dir = 'images/property_pics/';
>$file = array();
>  if(is_dir($dir)){
>   if($open = opendir($dir)){
> 
> while (($file = readdir($open)) !== false && $file !== ".") {
> 
>   $names = substr($file, 9, 20);
>   echo $names;
> 
>   }
> 
>   }
>  closedir($handle);
>}
> } 
> 
> $rs = $pager->paginate();
>  if(!$rs) die(mysql_error());
>  while($row = mysql_fetch_assoc($rs)) {
> 
> 
>echo "";
>echo "";
>echo 
> 
> What I am trying to do is get the last part of an image name, because I know 
> the $MSL_No is always a 9 character name which matches the image name in 
> but in the database, the last bit of characters are not there so I'm trying 
> to 
> take the last characters of the image name and concatinate them to each 
> image name..
> 
> Wow this is harder to explain that I thought. Here's an example
> 
> In the DB I have a row MSL_No and the contents is: 123456789
> 
> In my images folder I have an image named 123456789_R13_1.jpg
> 
> My goal: get the MSL_No out of the DB and concatenate anything after it so I 
> would end up with the whole image name..
> 
> I hope this all made sense. :-/

Is there just one image in the folder that starts with the 9 digit number? In 
that case it's dead simple (untested code):

';
?>

If you need to extract more than one image filename you should be able to 
modify that pretty easily.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] a little trickery

2012-09-08 Thread David McGlone
I have a function that reads a directory and gets all the file names of images, 
and I am wondering if it's possible to concatinate this function withint an 
image tag. Here's an example I tried.

function pictures() {

$dir = 'images/property_pics/';
$file = array();
  if(is_dir($dir)){
if($open = opendir($dir)){
  
  while (($file = readdir($open)) !== false && $file !== ".") {
  
$names = substr($file, 9, 20);
echo $names;

}
   
}
  closedir($handle);
}
} 

$rs = $pager->paginate();
  if(!$rs) die(mysql_error());
  while($row = mysql_fetch_assoc($rs)) {
 
   
echo "";
echo "";
echo 

What I am trying to do is get the last part of an image name, because I know 
the $MSL_No is always a 9 character name which matches the image name in 
but in the database, the last bit of characters are not there so I'm trying to 
take the last characters of the image name and concatinate them to each 
image name..

Wow this is harder to explain that I thought. Here's an example

In the DB I have a row MSL_No and the contents is: 123456789

In my images folder I have an image named 123456789_R13_1.jpg

My goal: get the MSL_No out of the DB and concatenate anything after it so I 
would end up with the whole image name..

I hope this all made sense. :-/ 

-- 
Regards
David M.