RE: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
Sure, I'll break it apart a little:

'{(?=|\s)(?!.*|\s)))}is'

$regex = '{' . // opening delimeter
 '(?=' .   // positive lookahead: match the beginning of a position 
   // that matches the following pattern:
 ' tag
 '(?:' . // non-capturing parenthesis (same as normal 
 // parenthesis, but a bit faster since we don't 
 // need to capture what they match for use later
 '>|\s' . // match a closing > or a space
 ')' . // end capturing paranthesis
 '(?!' . // negative lookahead: the match will fail if the
//following pattern matches from the current position
 '.*' .  // match until the end of the string
 '|\s)' . // same as above - look for another  tag
 ')' .  // end negative lookahead
 ')' .  // end positive lookahead
 '}is';   // ending delimeter, and use modifiers s and i

About the modifiers: i makes it case-insensitive, and s turns on
dot-matches-all-mode (including newlines)--otherwise, the . would only match
until the next newline.

The regex has two parts: matching a  tag, and then making sure there
aren't any more  tags in the string following it. The positive lookahead
is (hopefully) pretty straightforward. The negative lookahead works by using
a greedy (regular) .*, which forces the regex engine to match all the way to
the end of the haystack. Then it encounters the \s) part, forcing it
to backtrack until it finds a  tag. If it doesn't find one before
returning to the 'current' position (directly after the  tag we just
matched), then we know we have found the last  tag.

The positive and negative lookahead are 'zero-width' requirements, which
means they don't advance the regex engine's pointer in the haystack string.
Since the entire regex is zero-width, the replacement string gets inserted
at the matched position. 

I hope that made at least a little bit of sense :) If you're doing a lot of
regex work, I would strongly recommend reading the book Mastering Regular
Expressions by Jeffrey Friedl... it's very well written and very helpful.

-Brian

-Original Message-
From: Dotan Cohen [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 27, 2007 3:45 PM
To: Brian Rue
Cc: php-general@lists.php.net
Subject: Re: [PHP] Adding text before last paragraph

On 27/08/07, Brian Rue <[EMAIL PROTECTED]> wrote:
> Dotan, try this:
>
> $text="First paragraph\nMore text\nSome more
> text\nEnd of story";
>
> $story = preg_replace('{(?=|\s)(?!.*|\s)))}is', "new
> paragraph goes here\n", $text);
>
> This matches a position that has an opening  tag (with or without
> parameters), which is NOT followed anywhere in $text by another opening

> tag. The replacement string will be inserted at the matched position,
which
> will be directly before the last  tag. Not sure if this is the most
> efficient regex, but it should get the job done. Let me know how it
goes...
> I'd also be interested to hear any comments on that regex's efficiency.
>
> -Brian Rue
>

Thank you Brian. This most certainly works. I'm having a very hard
time decyphering your regex, as I'd like to learn from it. I'm going
over PCRE again, but I think that I may hit google soon. Thank you
very, very much for the working code. As usual, I have another night
of regex waiting for me...

Dotan Cohen

http://lyricslist.com/
http://what-is-what.com/

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



Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
Dotan, try this:

$text="First paragraph\nMore text\nSome more
text\nEnd of story";

$story = preg_replace('{(?=|\s)(?!.*|\s)))}is', "new
paragraph goes here\n", $text);

This matches a position that has an opening  tag (with or without
parameters), which is NOT followed anywhere in $text by another opening 
tag. The replacement string will be inserted at the matched position, which
will be directly before the last  tag. Not sure if this is the most
efficient regex, but it should get the job done. Let me know how it goes...
I'd also be interested to hear any comments on that regex's efficiency.

-Brian Rue


Dotan Cohen wrote:

> On 27/08/07, Richard Lynch <[EMAIL PROTECTED]> wrote:
>> On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote:
>> > I have a string with some HTML paragraphs, like so:
>> > $text="First paragraph\nMore text\nSome more
>> > text\nEnd of story";
>> >
>> > I'd like to add an image before the last paragraph. I know that
>> > preg_replace can replace only the first n occurrences of a string, but
>> > how can I replace the _last_ occurrence of a string? My initial idea
>> > was to do this:
>> > 1) Count how many  times "\n" occurs as $n
>> > 2) Replace them all with  "\n\n"
>> > 3) Replace $n-1 replacements back to "\n"
>> >
>> > Is there a cleaner way? Thanks in advance.
>>
>> If the string really really ENDS on that LAST "", then you can key
>> off of that:
>>
>> $story = preg_replace("|(.*\$|Umsi",
>> "$new_paragraph\n\\1", $story;
>>
>> You may have to fiddle with the DOT_ALL setting to only match the true
>> end of string and not just any old "\n" within the string...
>> http://php.net/pcre
>>
> 
> Thanks, Richard, I was also trying to use a regex with pre_replace and
> getting nowhere. In the manual page for strrpos, there is a
> user-comment function for finding the last occurrence of a string:
> http://il2.php.net/manual/en/function.strrpos.php#56735
> 
> However, I am unable to piece 2 and 2 together.
> 
> Note that I'm adding a paragraph before the last paragraph, so I'm
> searching for the last instance of "\n".
> 
> This is what I've done to your code, but I'm unable to get much further:
> $text = preg_replace("|(\n)\$|Umsi", "\nTest\n",
> $text);
> 
> Dotan Cohen
> 
> http://lyricslist.com/
> http://what-is-what.com/

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



[PHP] Re: CURL receiving content data

2007-08-24 Thread Brian Rue
Bruce, I tried using curl to just get the feed and it worked ok:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 
  'http://api.beta.blogs.aol.com/bsteinback0224/service.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
print curl_exec($ch);

My guess would be that one or more of the extra headers you're sending are
causing the server to get confused... i.e. maybe you're missing a slash in
the referer, or you're otherwise not sending the exact headers the server is
expecting. The Live HTTP Headers firefox extension has been really helpful
for me; give it a try if you haven't already.

Good luck...

-Brian Rue

Bruce Steinback wrote:

> Hi all,
> 
> First thanks to the people that corrected my dumb mistake on XML parsing a
> few weeks ago, and let's hope that this is as dumb.
> 
> I've got a mashup that when contacted attempts to gather feed info to mash
> into it's response.  I send a GET request (Atom request to be exact), and
> get the following back:
> 
> HTTP/1.0 200 OK Date: Thu 23 Aug 2007 21:27:48 GMT Server: Apache/2.0.54
> (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7e mod_jk/1.2.14 Content-Length: 222
> Connection: close Content-Type: application/atomsvc+xml;charset=UTF-8
> 
> but no Content data (the Atom XML response in the Content-Type).
> 
> Here's my code:
> $checkBlogsUrl = "http://api.beta.blogs.aol.com/"; . $owner .
> "/service.xml"; $sessionRequest = curl_init();
> curl_setopt( $sessionRequest, CURLOPT_URL, $checkBlogsUrl);
> curl_setopt( $sessionRequest, CURLOPT_RETURNTRANSFER, true );
> curl_setopt( $sessionRequest, CURLOPT_REFERER, $baseUrl .
> "loginresp-blogs.php"); $header[] = "X-AOL-DEVID: " . $devId;
> $header[] = "Authorization=OpenAuth token: " . $token;
> curl_setopt( $sessionRequest, CURLOPT_HTTPHEADER, $header);
> curl_setopt( $sessionRequest, CURLOPT_HEADER, 1);
> $responseBase = curl_exec( $sessionRequest );
> //$responseXml = curl_multi_getcontent($sessionRequest);
> print "" . $responseBase;
> 
> As you can see, I tried curl_multi_content hoping it might be for like
> multiple content, but in reviewing the spec, it's obviously for
> aggregating multiple requests.
> 
> There's definitely content there, you can try:
> http://api.beta.blogs.aol.com/bsteinback0224/service.xml
> to see it.  And the Content-Length figure looks about right (it was 847
> for bsteinback0224, which was pretty close to the file size when I saved
> it).
> 
> I can find dozens of examples of adding POST Content, but none for reading
> file content.  Please don't tell me it can't be done :-(
> 
> Thanks,
> Bruce
> 
> 
> 
> 
>
>

> Pinpoint customers who are looking for what you sell.
> http://searchmarketing.yahoo.com/

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



[PHP] Re: [PHP-DB] Re: [PHP] Passing variables to a PHP script on clicking a hyperlink

2007-08-24 Thread Brian Rue
In this case $_POST would be the appropriate array, since your form is
using the POST method:



Goltsios Theodore wrote:

> 
> I thought I just did a comment and suggested that it is a lame solution
> to use $_REQUEST plus I did not know witch of the two method  (POST or
> GET) would be appropriate so I picked up the lame way :-) .
> 
> mike wrote:
>> On 8/24/07, Goltsios Theodore <[EMAIL PROTECTED]> wrote:
>>   
>>> the posted or got option buy using the $_REQUEST array ($_GET and $_POST
>>> are included in that like a less lame solution). Let's say you have a
>>> 
>>
>> Please do not encourage the use of $_REQUEST.
>>
>> You might as well just tell people to enable register_globals again.
>>
>> Use $_GET, $_POST, $_SESSION, $_COOKIE, $_SERVER, etc. for the
>> appropriate source of data. $_REQUEST is laziness and introduces most
>> of the same issues that was the reasoning behind disabling
>> register_globals to begin with.
>>
>> (As for dropdowns, that's just an in-browser method of collecting data
>> and sending the key/value pairs in POST or GET... IMHO the HTML
>> portion should already be known before someone steps into the realm of
>> PHP and server-side programming)
>>
>> - mike
>>
>>

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



[PHP] symlinks

2003-07-03 Thread Brian Rue
Hi,

I need to link a url like this:

www.mysite.com/?id=5

to a folder like this:

www.mysite.com/5

(so that I can access it from the subdomain 5.mysite.com)

I'm assuming that symlinks are the best way to do this, but I really don't
know how to do it.

Any help is greatly appreciated.

Thanks



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



Re: [PHP] Beginner question?

2001-12-21 Thread Brian Rue

>>Can anyone show me how to split() each line and parse to see if $user
exists?<<

// get contents of a file into a string
$filename = "./users.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);

// seperate the string into an array of lines
$linebreak = "\n";
$lines = explode($linebreak,$contents);

// seperate each line into an array of words
for ($i=0;$i
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 20, 2001 10:59 PM
Subject: Re: [PHP] Beginner question?


Michael,

$fp = fopen ("./users.txt", "r");
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

Ok. But $buffer is not an array, is it? Why/what is 4096? What is !feof ?

Can anyone show me how to split() each line and parse to see if $user
exists?

Here's what I'm upto. I want to use users.txt as a user:password text
database
file.
I want to read users.txt into an array.
I want to parse each line splitting for ":"

user:pass
john:help
michael:thanks

$fp = fopen ("./users.txt", "r");
while (!feof ($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 }
fclose($fp);

$user = "john";
$num_fields = count($buffer);
for ($i = 0; $i < $num_fields; $i++)
{
if ?? = $user then echo ??
}

Can anyone show me how to split() each line and parse to see if $user
exists?


> > >$fp = fopen ("./info.txt", "r");
> >print $fp;
> >fclose($fp);
> >?>

> $fp is just a file pointer, not the actual contents of the file.  You need
> to use fgets() (or something similar) to actually get the contents out.
> http://www.php.net/manual/en/function.fgets.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Counting "Views" on records in DB!

2001-12-21 Thread Brian Rue

Add a column to your messages table called "views". Whenever you read the
message (SELECT message FROM messages_table WHERE messageid='id';),
increment the column for that row (UPDATE messages_table SET views = views +
1 WHERE messageid='id';).
- Original Message -
From: "Thomas Edison Jr." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, December 21, 2001 12:46 PM
Subject: Re: [PHP] Counting "Views" on records in DB!


Hi,

> UPDATE $table views=views+1

Umm.. can you be a little more specific. I couldn't
make much sense, thought i could get the logic.
Thanks.

T. Edison jr.

> > Hi,
> > I was just going through some Message Board system
> and
> > noticed that there is a "Views" column which gives
> how
> > many times the Message has been viewed.
> >
> > I created a similar message board, where Messages
> are
> > stored in a MySQL DB Table. But i have no idea how
> to
> > do this, that the number of times that Record is
> > picked up is counted!! Can anyone guide me as to
> how
> > this can be achieved?
> >
> > Thanks,
> > T. Edison jr.
> >
> >
> > __
> > Do You Yahoo!?
> > Send your FREE holiday greetings online!
> > http://greetings.yahoo.com


=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mysql_query() problem

2001-12-16 Thread Brian Rue

Hi,

I'm getting the error
<>

from this code:

function validateUser($username,$password) {
 $conn = connectToMySQL();
 mysql_select_db($db_name,$conn);
 $query="select * from members where username='".$username."' AND
password='".$password."'";
 $result = mysql_query($query,$conn);
 if (mysql_num_rows($result) != 0) { //*this is the line that returns the
error*
   return true;
 } else {
   return false;
 }
}

I've checked that the connection works, and that the query is what it should
be, and the query works when I type it into the terminal. Any ideas?

Thanks,
Brian Rue



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] MySQL problem...

2001-04-25 Thread Brian Rue

Here's all the code that uses MySQL...

 $db = mysql_connect("localhost","user","pass");
  mysql_select_db("db",$db);
  $gmdquery="SELECT * FROM game_of_the_day";
  $the_info = mysql_query($gmdquery,$db);

while ($myrow = mysql_fetch_row($the_info)) {
(get info from the result)
}

... (decide whether or not to conduct the following operation)

if (true) {
   $query="SELECT id FROM games WHERE rating >= 7";
   $result=mysql_query($query,$db);
   $numgames=mysql_num_rows($result);
   $z=0;
   while ($row=mysql_fetch_row($result)){
$gotd_cand[$z]=$row[0];
$z++;
   }

   (at this point, i randomly select 2 games from the db)

 $query="SELECT genre,number FROM games WHERE id=$game1_to_get";
 $gameinfo=mysql_query($query,$db);
 while($row=mysql_fetch_row($gameinfo)){
  (use the result)
 }

(do the same thing as before, but for the second game)


   }
  (update the db)
   $query="DELETE FROM game_of_the_day";
   $result=mysql_query($query,$db);


   $query="INSERT INTO game_of_the_day VALUES
('',$curr_yday,'$gameone_genre',$gameone_number,'$gametwo_genre',$gametwo_nu
mber)";
   $result=mysql_query($query,$db);

  }



Keep in mind that this only happens some of the time... sometimes it works,
and sometimes it just doesn't.


Today, I noticed that it stored the first game into the db twice (the code
doesn't allow for the same game to be selected twice...)



Thanks for your time


""Peter Houchin"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> some code would be nice to have a look at :)
>
> Other than that, check table names, database names, also your result
lines, I've found i get that error by not calling a result or calling the
incorrect table/database
>
> Peter
>
> -Original Message-
> From: Brian Rue [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 26, 2001 10:28 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] MySQL problem...
>
>
> MySQL doesn't like me
>
> Sometimes, my pages that connect to the database get the error "Warning:
> Supplied argument is not a valid MySQL result resource..." repeated over
and
> over again (something like 1000 times...)
>
> What's causing this error? Obviously, PHP isn't getting a result back from
> MySQL... and it keeps trying to get it.
>
> Any help?
>
>
> Thanks,
> Brian Rue
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] MySQL problem...

2001-04-25 Thread Brian Rue

MySQL doesn't like me

Sometimes, my pages that connect to the database get the error "Warning:
Supplied argument is not a valid MySQL result resource..." repeated over and
over again (something like 1000 times...)

What's causing this error? Obviously, PHP isn't getting a result back from
MySQL... and it keeps trying to get it.

Any help?


Thanks,
Brian Rue



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]