php-general Digest 30 Jul 2009 08:06:56 -0000 Issue 6257

Topics (messages 296015 through 296049):

Re: Getting rid of extra lines
        296015 by: Ashley Sheridan
        296016 by: Bob McConnell
        296020 by: Jim Lucas
        296021 by: Miller, Terion
        296022 by: Miller, Terion
        296023 by: Jim Lucas
        296025 by: Jonathan Tapicer

Re: preg_match too greedy
        296017 by: Ben Dunlap
        296019 by: Jim Lucas
        296041 by: Clancy
        296042 by: Daniel Kolbo
        296043 by: b
        296044 by: b
        296045 by: b
        296047 by: Daniel Kolbo
        296048 by: b

Asterisk anyone?
        296018 by: Skip Evans
        296024 by: Per Jessen
        296038 by: Skip Evans
        296049 by: Sancar Saran

Re: Getting rid of extra lines (RESOLVED)
        296026 by: Miller, Terion
        296027 by: Jim Lucas
        296029 by: Miller, Terion

Locating Bad Image Files
        296028 by: Floyd Resler

Expand Variables in String
        296030 by: Daniel Kolbo
        296033 by: Jonathan Tapicer
        296039 by: Daniel Kolbo
        296040 by: Jonathan Tapicer

Re: Ridiculous ..won't print or echo ...(RESOLVED)
        296031 by: Miller, Terion

Page or URL function?
        296032 by: Miller, Terion
        296035 by: Ben Dunlap
        296036 by: Ben Dunlap
        296037 by: Ben Dunlap

fileinfo returning wrong mime type for Excel files
        296034 by: Christoph Boget
        296046 by: Paul M Foster

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
From: Miller, Terion

/* snip */

Before anyone can tell you how to fix it, you need to find out what is
causing that white space. is it empty lines, vertical tabs, thousands of
spaces, ...? Once you find that out, it is pretty easy to decide how to
get rid of them. Can you save the output to a file and open it with a
hex viewer?

Bob McConnell

--- End Message ---
--- Begin Message ---
Miller, Terion wrote:
> I am trying to get rid of empty whitespace lines, I can't us chop() because
> as I read it it will remove all whitespaces....right?
> 
> Right now my db is outputting with extra lines, I have stripped tags I know
> it isn't that causing it to look like this
> 
> Blahlajdlkfjlksdjflkdjsf
> 
>                <--------------how do I get rid of all this extra space?
> 
> alkdfjlsdakjflsakdjflksjdf
> 
> 

If the white space is included in data coming from the db you could run
a simple little regex on the variable to removed any repetitive white
space.  But it might not be the best way to do it.

        $clean = preg_replace('|\s+|', ' ', $input);
or
        $clean = preg_replace('|\s{2,}|', ' ', $input);

If the white space is being generated in your HTML output, but is not in
your data store, then you need to cleanup your PHP code and that might help.


--- End Message ---
--- Begin Message ---


On 7/29/09 1:45 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk



Yep I have tried str_replace to get rid of \n and it didn't work
Boss mentioned to explode the var that is full of so many blank lines then put 
it back together..seems like there has to be an easier way...

This is what I tried:

     $tags = array('\n', '<br>');    $sNotes = str_replace($tags,"", $notes);

--- End Message ---
--- Begin Message ---


On 7/29/09 2:19 PM, "Jim Lucas" <li...@cmsws.com> wrote:

$clean = preg_replace('|\s+|', ' ', $input);

Hi Jim,
The extra whitespace lines are in the data store, coming from it I'm going to 
try your method but is there a way to not have mySQL store it with so many 
lines (this is data being screen scraped and put in the db)
My code was at the beginning of this post of how I was inserting it.

Thanks
And Chocolate huh....
Terion

--- End Message ---
--- Begin Message ---
Miller, Terion wrote:
> 
> 
> On 7/29/09 2:19 PM, "Jim Lucas" <li...@cmsws.com> wrote:
> 
> $clean = preg_replace('|\s+|', ' ', $input);
> 
> Hi Jim,
> The extra whitespace lines are in the data store, coming from it I'm going to 
> try your method but is there a way to not have mySQL store it with so many 
> lines (this is data being screen scraped and put in the db)
> My code was at the beginning of this post of how I was inserting it.
> 
> Thanks
> And Chocolate huh....
> Terion
> 

If the method that I give you works on the out from the db to the
browser, the should be no reason you cannot adapt whatever script you
are using for scrapping to use this function when it inserts the data
into the db.

Jim


--- End Message ---
--- Begin Message ---
On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
>
>
>
> On 7/29/09 1:45 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> [snip/]
>
> Have you thought of just using a regular str_replace() on your code? You
> can ask it to replace newlines and carriage returns with nothing and see
> if that fixes you problem?
>
> Thanks
> Ash
> www.ashleysheridan.co.uk
>
>
>
> Yep I have tried str_replace to get rid of \n and it didn't work
> Boss mentioned to explode the var that is full of so many blank lines then 
> put it back together..seems like there has to be an easier way...
>
> This is what I tried:
>
>     $tags = array('\n', '<br>');    $sNotes = str_replace($tags,"", $notes);
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

That didn't work because \n needs to be between " " instead of ' '.

Jonathan

--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
>> I expected 'no match' but get 'match'.
[8<]
> cut/paste your code and it works for me.

Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?

If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:

>> $url = '/foo(/)?';

I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.

>> echo (preg_match($pattern, $test) != false)

The " != false " here is redundant. Combined with the ternary operator, the
logical switchbacks make me a little dizzy (especially this close to lunchtime).

Ben

--- End Message ---
--- Begin Message ---
Ben Dunlap wrote:
> Jim Lucas wrote:
>>> I expected 'no match' but get 'match'.
> [8<]
>> cut/paste your code and it works for me.
> 
> Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
> version do you have?

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
  with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project


> 
> If I might suggest a couple of simplifications that would make it easier to
> follow/troubleshoot:
> 
>>> $url = '/foo(/)?';
> 
> I don't think you need parentheses around your second forward-slash. If you 
> had
> multiple characters that were optional you'd want to group them in 
> parentheses,
> but here I think it just makes the regex harder to read.
> 
>>> echo (preg_match($pattern, $test) != false)
> 
> The " != false " here is redundant. Combined with the ternary operator, the
> logical switchbacks make me a little dizzy (especially this close to 
> lunchtime).
> 
> Ben
> 



--- End Message ---
--- Begin Message ---
On Wed, 29 Jul 2009 13:42:23 -0400, p...@logi.ca (b) wrote:

>I'm trying to figure out how to test if a string matches *exactly* 
>another string, using a regexp pattern. 

If this is REALLY what you want to do, what is wrong with strcmp?


--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
> Ben Dunlap wrote:
>> Jim Lucas wrote:
>>>> I expected 'no match' but get 'match'.
>> [8<]
>>> cut/paste your code and it works for me.
>> Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
>> version do you have?
> 
> PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
> Copyright (c) 1997-2007 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
>   with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project
> 
> 
>> If I might suggest a couple of simplifications that would make it easier to
>> follow/troubleshoot:
>>
>>>> $url = '/foo(/)?';
>> I don't think you need parentheses around your second forward-slash. If you 
>> had
>> multiple characters that were optional you'd want to group them in 
>> parentheses,
>> but here I think it just makes the regex harder to read.
>>
>>>> echo (preg_match($pattern, $test) != false)
>> The " != false " here is redundant. Combined with the ternary operator, the
>> logical switchbacks make me a little dizzy (especially this close to 
>> lunchtime).
>>
>> Ben
>>
> 
> 
> 
code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'
This time preg_match fails due to the end of line anchor.
hth
dK
`

--- End Message ---
--- Begin Message ---
On 07/29/2009 02:07 PM, Jim Lucas wrote:
b wrote:
I'm trying to figure out how to test if a string matches *exactly*
another string, using a regexp pattern. The manual says that ereg() is
deprecated (in favour of what?) and preg_match() is giving me trouble.
The problem is that I'm passing the end-of-line delimiter ($) but it
seems to be ignored. An example:

-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo "${url} :: ${test}\n";

echo (preg_match($pattern, $test) != false)
     ? 'match'
     : 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a
'$' to specify that I want to test for the exact string. However,
preg_match() tests for the existence of a string and appears to ignore
the '$'.

How do I do this?


cut/paste your code and it works for me.

Jim Lucas


Works, meaning you get 'match', or 'no match'? It should be the latter, but I'm seeing the former.

I'm using 5.2.9, btw.

--- End Message ---
--- Begin Message ---
On 07/29/2009 03:03 PM, Ben Dunlap wrote:
Jim Lucas wrote:
I expected 'no match' but get 'match'.
[8<]
cut/paste your code and it works for me.

Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?

5.2.9

If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:

$url = '/foo(/)?';

I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.

Really? I think it makes it crystal clear that it's the '/' that is optional. In any case, it makes no difference.


echo (preg_match($pattern, $test) != false)

The " != false " here is redundant.

Understood. But what you think is redundancy is, to me, clarity in programming. I happen to think that boolean tests shouldn't ride on whether or not an array returned from a function is empty or not (or a freaking boolean). If what I'm looking for is a "false" then that's what I'll test for.

Combined with the ternary operator, the logical switchbacks make me a
> little dizzy (especially this close to lunchtime).


Oh, you're one of those people who can't stand the sight of a ternary operator. Buck up, son, it's good for ya ;-)

(Seriously: I don't understand why ternaries freak some people out. It's plain as day!)


--- End Message ---
--- Begin Message ---
On 07/29/2009 07:48 PM, Daniel Kolbo wrote:

code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

The forward slash shouldn't be an issue as the delimiter is '%'. The full pattern is:

%^/foo/?$%U


Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'

But the string happens to start with a forward slash.


--- End Message ---
--- Begin Message ---
b wrote:
> On 07/29/2009 07:48 PM, Daniel Kolbo wrote:
>>
>> code works (no match) for me too on php 5.2.6 build date May 2 2008
>> 18:01:20 with dumbdows NT.
>>
>> preg_match fails but for a reason other than what I think you may be
>> expecting.  It fails b/c of the first forwards slash in $url.  The regex
>> engine doesn't even get past the second character let alone reaching the
>> end of line anchor.
> 
> The forward slash shouldn't be an issue as the delimiter is '%'. The
> full pattern is:
> 
> %^/foo/?$%U
> 
> 
>> Also, your code works (no match) with this first forward slash removed:
>> $url = 'foo(/)?'
> 
> But the string happens to start with a forward slash.
> 
> 
i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'

the first character of your pattern is a "/" and your first character of
your test string is an "f".  They do not match.  The regex engine stops
after checking the first character.  This has nothing to do with
greediness or end of line anchors, but only with the first character
comparisons.

maybe what you wanted for your test string was
'/foo/bar'

This test string would then require your end of line anchor. Because the
end of line character does not match the "b" the engine stops.  No match.

This is consistent with the findings of others who replied to you.

Perhaps your regex engine has a different syntax for anchors.  For
example if your engine was seeing the carrot as a an exclusion operator
rather than being a beginning of line anchor and it was also, idk,
ignoring the dollar sign as your end of line anchor then you would get a
match.  But otherwise I would recommend you copy/paste the example you
provided and confirm that you still get a match.  Then i would confirm
your regex engine's anchor syntax.  Then, recompile your software....
dK
`

--- End Message ---
--- Begin Message ---
On 07/29/2009 11:18 PM, Daniel Kolbo wrote:
b wrote:
On 07/29/2009 07:48 PM, Daniel Kolbo wrote:
code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.
The forward slash shouldn't be an issue as the delimiter is '%'. The
full pattern is:

%^/foo/?$%U


Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'
But the string happens to start with a forward slash.


i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'

AAARRRGGHHHH! Sorry, that's a typo! It should be:

$test = '/foo/bar';

I guess that explains a lot. For the record, I had to type that in because this latest version of Thunderbird crashes whenever I paste into it. (note to self: downgrade that, stat!)





--- End Message ---
--- Begin Message ---
Hey,

I've been asked to write a simple couple of public pages that would let an Asterisk customer modify their account configuration, but the client has no idea how Asterisk stores its data, apparently not in MySQL.

Anyone know of any resources for accessing Asterisk from PHP?

If anyone has done this can you tell me if I'm on the right track here?

http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples

--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

--- End Message ---
--- Begin Message ---
Skip Evans wrote:

> Hey,
> 
> I've been asked to write a simple couple of public pages that
> would let an Asterisk customer modify their account
> configuration, but the client has no idea how Asterisk stores
> its data, apparently not in MySQL.

Depends on which data we're talking about.  Asterisk is very flexible.

> Anyone know of any resources for accessing Asterisk from PHP?
> 
> If anyone has done this can you tell me if I'm on the right
> track here?
> 
> http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples

That's definitely the right place to go, but it's not exactly enough to
asnwer your question. 

/Per

-- 
Per Jessen, Zürich (27.8°C)


--- End Message ---
--- Begin Message ---
Per Jessen wrote:
Depends on which data we're talking about.  Asterisk is very flexible.


For example, the first screen they want people to be able to change data on is:

call waiting,do not disturb
and then it looks like numbers (forwarding?)
unconditional,unavailable,busy

I'm trying to figure out now are these values stored in a regular relational database like MySQL.

But so far the documentation I see is really all about how to handle calls, not manage customer data.

--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

--- End Message ---
--- Begin Message ---
On Wednesday 29 July 2009 10:18:08 pm Skip Evans wrote:
> Hey,
>
> I've been asked to write a simple couple of public pages that
> would let an Asterisk customer modify their account
> configuration, but the client has no idea how Asterisk stores
> its data, apparently not in MySQL.
>
> Anyone know of any resources for accessing Asterisk from PHP?
>
> If anyone has done this can you tell me if I'm on the right
> track here?
>
> http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples

Hello,

Asterisk's default storage was text files.

You should check Trixbox. 

It was a Asterisk with MySQL backend. Also it has all bells and whistles. And 
web based management console.

Even it comes packed with a centos.

Your link shows how to remote asterisk console from web.

Regards

--- End Message ---
--- Begin Message ---


On 7/29/09 3:05 PM, "Jonathan Tapicer" <tapi...@gmail.com> wrote:

On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
>
>
>
> On 7/29/09 1:45 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> [snip/]
>
> Have you thought of just using a regular str_replace() on your code? You
> can ask it to replace newlines and carriage returns with nothing and see
> if that fixes you problem?
>
> Thanks
> Ash
> www.ashleysheridan.co.uk
>
>
>
> Yep I have tried str_replace to get rid of \n and it didn't work
> Boss mentioned to explode the var that is full of so many blank lines then 
> put it back together..seems like there has to be an easier way...
>
> This is what I tried:
>
>     $tags = array('\n', '<br>');    $sNotes = str_replace($tags,"", $notes);
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

That didn't work because \n needs to be between " " instead of ' '.

Jonathan


Thanks Guys, ended up using Jim's way before inserting it into the db and it 
works like a charm


--- End Message ---
--- Begin Message ---
Miller, Terion wrote:
> 
> 
> On 7/29/09 3:05 PM, "Jonathan Tapicer" <tapi...@gmail.com> wrote:
> 
> On Wed, Jul 29, 2009 at 4:20 PM, Miller,
> Terion<tmil...@springfi.gannett.com> wrote:
>>
>>
>> On 7/29/09 1:45 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>>
>> [snip/]
>>
>> Have you thought of just using a regular str_replace() on your code? You
>> can ask it to replace newlines and carriage returns with nothing and see
>> if that fixes you problem?
>>
>> Thanks
>> Ash
>> www.ashleysheridan.co.uk
>>
>>
>>
>> Yep I have tried str_replace to get rid of \n and it didn't work
>> Boss mentioned to explode the var that is full of so many blank lines then 
>> put it back together..seems like there has to be an easier way...
>>
>> This is what I tried:
>>
>>     $tags = array('\n', '<br>');    $sNotes = str_replace($tags,"", $notes);
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 
> That didn't work because \n needs to be between " " instead of ' '.
> 
> Jonathan
> 
> 
> Thanks Guys, ended up using Jim's way before inserting it into the db and it 
> works like a charm
> 
> 

Just to be clear.  Can you paste which one worked for you.


--- End Message ---
--- Begin Message ---


On 7/29/09 3:16 PM, "Jim Lucas" <li...@cmsws.com> wrote:

Miller, Terion wrote:
>
>
> On 7/29/09 3:05 PM, "Jonathan Tapicer" <tapi...@gmail.com> wrote:
>
> On Wed, Jul 29, 2009 at 4:20 PM, Miller,
> Terion<tmil...@springfi.gannett.com> wrote:
>>
>>
>> On 7/29/09 1:45 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>>
>> [snip/]
>>
>> Have you thought of just using a regular str_replace() on your code? You
>> can ask it to replace newlines and carriage returns with nothing and see
>> if that fixes you problem?
>>
>> Thanks
>> Ash
>> www.ashleysheridan.co.uk
>>
>>
>>
>> Yep I have tried str_replace to get rid of \n and it didn't work
>> Boss mentioned to explode the var that is full of so many blank lines then 
>> put it back together..seems like there has to be an easier way...
>>
>> This is what I tried:
>>
>>     $tags = array('\n', '<br>');    $sNotes = str_replace($tags,"", $notes);
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> That didn't work because \n needs to be between " " instead of ' '.
>
> Jonathan
>
>
> Thanks Guys, ended up using Jim's way before inserting it into the db and it 
> works like a charm
>
>

Just to be clear.  Can you paste which one worked for you.

This is what worked....on my page that inserts the data to the db I put

 //stripping white line spaces    $cleanNotes = preg_replace('|\s+|', ' ', 
$notes);    $cleanVios = preg_replace('|\s+|', ' ', $cleanViolations);

then I mysql_escaped them and put them in the db, checked the csv and presto 
perfect no extra linespacing


--- End Message ---
--- Begin Message --- I use convert to create thumbnail images. However, we have several PDFs that convert doesn't seem to like. Even though it produced error messages it still creates the thumbnail which doesn't display an image. Is there an easy way for me to identify those bad image files somehow in PHP by examining the content?

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
Hello,

Is it possible to force a string to expand variable names after the
string has been set and before the variable's been defined without
having to do a string replace or preg_replace?

for example,
<?php
$str = "some string and some \$var plus other stuff";
echo $str."<br />";
$var = "Variable Contents";
echo $str."<br />";
$str_expanded = $str;//would like this to expand $var into $str_expanded
echo $str_expanded."<br />";
?>

Thanks,
dK
`

--- End Message ---
--- Begin Message ---
Use eval, like this:

eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";');

The str_replace is used because you could have a " inside $str and it
would break the string, if you are sure the $str has no " inside you
can omit it.

Jonathan

On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbo<kolb0...@umn.edu> wrote:
> Hello,
>
> Is it possible to force a string to expand variable names after the
> string has been set and before the variable's been defined without
> having to do a string replace or preg_replace?
>
> for example,
> <?php
> $str = "some string and some \$var plus other stuff";
> echo $str."<br />";
> $var = "Variable Contents";
> echo $str."<br />";
> $str_expanded = $str;//would like this to expand $var into $str_expanded
> echo $str_expanded."<br />";
> ?>
>
> Thanks,
> dK
> `
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Jonathan Tapicer wrote:
> Use eval, like this:
> 
> eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";');
> 
> The str_replace is used because you could have a " inside $str and it
> would break the string, if you are sure the $str has no " inside you
> can omit it.
> 
> Jonathan
> 
> On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbo<kolb0...@umn.edu> wrote:
>> Hello,
>>
>> Is it possible to force a string to expand variable names after the
>> string has been set and before the variable's been defined without
>> having to do a string replace or preg_replace?
>>
>> for example,
>> <?php
>> $str = "some string and some \$var plus other stuff";
>> echo $str."<br />";
>> $var = "Variable Contents";
>> echo $str."<br />";
>> $str_expanded = $str;//would like this to expand $var into $str_expanded
>> echo $str_expanded."<br />";
>> ?>
>>
>> Thanks,
>> dK
>> `
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 
nice!

This would allow me to have $str loaded with all kinds of variables and
not have to do a str_replace with each (assuming the quote business is cool)

Why did you have the double \\?
> eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";');
Isn't the following equivalent?
eval('$str_expanded = "' . str_replace('"', '\"', $str) . '";');

Thanks,
dK
`

--- End Message ---
--- Begin Message ---
On Wed, Jul 29, 2009 at 6:47 PM, Daniel Kolbo<kolb0...@umn.edu> wrote:
> Jonathan Tapicer wrote:
>> Use eval, like this:
>>
>> eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";');
>>
>> The str_replace is used because you could have a " inside $str and it
>> would break the string, if you are sure the $str has no " inside you
>> can omit it.
>>
>> Jonathan
>>
>> On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbo<kolb0...@umn.edu> wrote:
>>> Hello,
>>>
>>> Is it possible to force a string to expand variable names after the
>>> string has been set and before the variable's been defined without
>>> having to do a string replace or preg_replace?
>>>
>>> for example,
>>> <?php
>>> $str = "some string and some \$var plus other stuff";
>>> echo $str."<br />";
>>> $var = "Variable Contents";
>>> echo $str."<br />";
>>> $str_expanded = $str;//would like this to expand $var into $str_expanded
>>> echo $str_expanded."<br />";
>>> ?>
>>>
>>> Thanks,
>>> dK
>>> `
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
> nice!
>
> This would allow me to have $str loaded with all kinds of variables and
> not have to do a str_replace with each (assuming the quote business is cool)
>
> Why did you have the double \\?
>> eval('$str_expanded = "' . str_replace('"', '\\"', $str) . '";');
> Isn't the following equivalent?
> eval('$str_expanded = "' . str_replace('"', '\"', $str) . '";');
>
> Thanks,
> dK
> `
>

Yes, it's the same, you can use only one \ in that case, sometimes you
have to escape if it is followed by a character that needs to be
escaped, for example you can't do echo '\'; you should do echo '\\';

Jonathan

--- End Message ---
--- Begin Message ---
Yep I forgot about escaping the $



On 7/29/09 10:51 AM, "Ford, Mike" <m.f...@leedsmet.ac.uk> wrote:

> -----Original Message-----
> From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
> Sent: 29 July 2009 16:36
>
> Ok in my output to Quark I need to have $P printed to the page like
> this:
>
> <@$p>2118 S. Campbell Ave
>
> So in my php which is going to be grabbing this info and formatting
> it for
> the Quark....isn't echoing that "$p" all I get is the <@>
>
> I have tried several things:
>
> $p = $p
>
> $p = print("$p")

"$p" is trying to interpolate the value of the variable $p -- if you had full 
error reporting turned on, you would see a nonexistent variable error. Once 
more, there are several things you can do, of which the two most obvious are:

* Use single quotes: echo '$p';

* Use a backslash: echo "\$p";


Cheers!

Mike
 --
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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




--- End Message ---
--- Begin Message ---
I've been searching php.net for a function to do this:

   if page_url('browse.php') {

    $default = "A";

                                                      }

$letter = isset($_GET['letter'])? $_GET['letter'] :"$default" ;

else
 {
                
    $letter = isset($_GET['letter'])? $_GET['letter'] :"" ;

                                                    }

I want to say if the page is browse, default to the A listings, if the page
is not browse show no default listings (because there is other data on the
page and I don't want this to output)

I thought there was url functions....am I calling it something different?
Terion


--- End Message ---
--- Begin Message ---
> I've been searching php.net for a function to do this:
> 
>    if page_url('browse.php') {

The $_SERVER global array has this sort of information. The 'PHP_SELF' key
might be what you want:

http://us.php.net/manual/en/reserved.variables.server.php

But where is the code that needs to know? I'm guessing it's in a common library
file that's going to be included in browse.php as well as other scripts, but am
I guessing rightly?

BTW, you could simplify your code slightly by defining $default as an empty
string before the IF block. Then you only have to read from $_GET once.

<?php
$default = "";
if (<url condition>) {
   $default = "A";
}
/*
 * No need for an "else" any more, now you can just
 * set the value of $letter
 */
?>

I'd also suggest using filter_input() rather than reading directly from $_GET:

<?php
$letter = filter_input(INPUT_GET, 'letter', <filter>, [<options>]);
if (empty($letter)) {
    $letter = $default;
}
?>

Presumably you'd want to use FILTER_VALIDATE_REGEXP in place of "<filter>" and,
for "<options>", pass a regex that ensures that 'letter' is a single
alphabetical character.

You can read about the filter functions here (sort of, the documentation is a
little sparse):

http://us.php.net/manual/en/ref.filter.php

A VALIDATE_REGEXP example is available here:

http://www.w3schools.com/php/filter_validate_regexp.asp

Ben

--- End Message ---
--- Begin Message ---
> I've been searching php.net for a function to do this:
> 
>    if page_url('browse.php') {

The $_SERVER global array has this sort of information. The 'PHP_SELF' key
might be what you want:

http://us.php.net/manual/en/reserved.variables.server.php

But where is the code that needs to know? I'm guessing it's in a common library
file that's going to be included in browse.php as well as other scripts, but am
I guessing rightly?

BTW, you could simplify your code slightly by defining $default as an empty
string before the IF block. Then you only have to read from $_GET once.

<?php
$default = "";
if (<url condition>) {
   $default = "A";
}
/*
 * No need for an "else" any more, now you can just
 * set the value of $letter
 */
?>

I'd also suggest using filter_input() rather than reading directly from $_GET:

<?php
$letter = filter_input(INPUT_GET, 'letter', <filter>, [<options>]);
if (empty($letter)) {
    $letter = $default;
}
?>

Presumably you'd want to use FILTER_VALIDATE_REGEXP in place of "<filter>" and,
for "<options>", pass a regex that ensures that 'letter' is a single
alphabetical character.

You can read about the filter functions here (sort of, the documentation is a
little sparse):

http://us.php.net/manual/en/ref.filter.php

A VALIDATE_REGEXP example is available here:

http://www.w3schools.com/php/filter_validate_regexp.asp

Ben

--- End Message ---
--- Begin Message ---
Ben Dunlap wrote [TWICE]:
> The $_SERVER global array has this sort of information. The 'PHP_SELF' key
[8<]
> Ben

Very sorry for the double-post. Reply-all in Thunderbird News seems a little
overzealous by default.

--- End Message ---
--- Begin Message ---
Consider the following:

        $finfo = finfo_open( FILEINFO_MIME, '/usr/share/file/magic' );
        if( $finfo )
        {
          $mimeType = finfo_file( $finfo, '/path/to/my/excel.xls' );
          finfo_close($finfo);
        }
        echo $mimeType;

When I run the above, it echoes out "application/msword".  Why?  I
understand that both excel and word are part of the office suite but
why isn't it returning "application/excel" as it should?  As far as I
can tell, we're using the most up to date version of fileinfo for PHP
5.2.5.  Is there something else I'm missing?  Or doing wrong?

thnx,
Christoph

--- End Message ---
--- Begin Message ---
On Wed, Jul 29, 2009 at 05:15:38PM -0400, Christoph Boget wrote:

> Consider the following:
> 
>         $finfo = finfo_open( FILEINFO_MIME, '/usr/share/file/magic' );
>         if( $finfo )
>         {
>           $mimeType = finfo_file( $finfo, '/path/to/my/excel.xls' );
>           finfo_close($finfo);
>         }
>         echo $mimeType;
> 
> When I run the above, it echoes out "application/msword".  Why?  I
> understand that both excel and word are part of the office suite but
> why isn't it returning "application/excel" as it should?  As far as I
> can tell, we're using the most up to date version of fileinfo for PHP
> 5.2.5.  Is there something else I'm missing?  Or doing wrong?
> 
> thnx,
> Christoph

Presumably, this information comes directly from /usr/share/file/magic.
FWIW, my copy of this file is in /usr/share/misc/file/magic, which is
where the man page says it should be. Debian Linux v5.

Paul

-- 
Paul M. Foster

--- End Message ---

Reply via email to