php-general Digest 31 Oct 2005 05:56:52 -0000 Issue 3767
Topics (messages 224846 through 224862):
Re: Substr by words
224846 by: Gustavo Narea
224849 by: Marcus Bointon
224861 by: Gustavo Narea
Fabforce 4.0.5.6 Beta
224847 by: Vizion
224848 by: Daniel Bowett
Using Ajax to spit out a php-generated embed tag
224850 by: Graham Anderson
224851 by: comex
un-eval()
224852 by: John Taylor-Johnston
224853 by: Chris Shiflett
224858 by: Robert Cummings
224860 by: John Taylor-Johnston
eval();
224854 by: John Taylor-Johnston
224855 by: Jasper Bryant-Greene
224856 by: John Taylor-Johnston
224857 by: Jasper Bryant-Greene
224859 by: John Taylor-Johnston
224862 by: Richard Lynch
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Other mistake in my last script.
Gustavo Narea wrote:
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
$replacement = preg_match("/^(\W*\b\w+\b){1,$MaxWords}/", '',
$MyOriginalString);
$result = substr( $MyOriginalString, 0, ($replacement) ?
-strlen($replacement) : strlen($MyOriginalString));
echo $result;
?>
Instead of preg_match(), I had to type preg_replace():
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
$replacement = preg_replace("/^(\W*\b\w+\b){1,$MaxWords}/", '',
$MyOriginalString);
$result = substr( $MyOriginalString, 0, ($replacement) ?
-strlen($replacement) : strlen($MyOriginalString));
echo $result;
?>
Best regards,
Gustavo Narea.
--- End Message ---
--- Begin Message ---
On 30 Oct 2005, at 15:35, Gustavo Narea wrote:
I think that trim($matches[0]) will return the whole string with no
change.
No, it will return the entire matching pattern, not just the sub-
matches. I added the trim to remove any leading space, and there will
nearly always be a trailing space because of the part of my pattern
that defines a word will include it. It was simpler to use trim than
to make the pattern skip it. Did you actually try it?
On the other hand, I think we have to place a caret after the first
slash.
Only if you insist that your string must start with a word - putting
a ^ at the start would make it omit the first word if there was a
space in front if it.
Instead of preg_match(), I had to type preg_replace():
err. I think you missed the point here. You don't need all that messy
substr stuff at all. The preg_match already did it.
Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk
--- End Message ---
--- Begin Message ---
Hello, Marcus.
Marcus Bointon wrote:
On 30 Oct 2005, at 15:35, Gustavo Narea wrote:
I think that trim($matches[0]) will return the whole string with no
change.
No, it will return the entire matching pattern, not just the sub-
matches. I added the trim to remove any leading space, and there will
nearly always be a trailing space because of the part of my pattern
that defines a word will include it. It was simpler to use trim than to
make the pattern skip it. Did you actually try it?
No. I said that I was not that sure about this because I have not used
preg_* functions yet.
On the other hand, I think we have to place a caret after the first
slash.
Only if you insist that your string must start with a word - putting a
^ at the start would make it omit the first word if there was a space
in front if it.
I think It is OK what I said about the caret, but what we need to change
is the position of \W*:
Your suggestion: /(\b\w+\b\W*){1,$MaxWords}/
My suggestion: /^(\W*\b\w+\b){1,$MaxWords}/
We need the *first* ($MaxWords)th words.
Instead of preg_match(), I had to type preg_replace():
err. I think you missed the point here. You don't need all that messy
substr stuff at all. The preg_match already did it.
Sorry, you are right. Maybe I thought I was talking about the former
script I suggested...
What do you think if we use the script you suggested, but we change the
regex to what I said above? It will look like:
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
$matches = array();
if (preg_match("/^(\W*\b\w+\b){1,$MaxWords}/", $MyOriginalString,
$matches)) {
$result = trim($matches[0]);
echo $result;
}
?>
Best regards,
Gustavo Narea.
--- End Message ---
--- Begin Message ---
I am trying to run Fabforce DBDesigner 4.0.5.6 Beta on:
win xp pro Version 2002 Service Pack 2
PHP 5.0.5
Mysql server 5.0.13 installed from 5.0.13-rc-win32.zip
and as Fabforce have closed their forum due to hacker problems I am hoping
someopne here might have some idea how to solve a problem.
I get a 'dbexpress' username/password failure on any attempt by DBDesigner to
connect to a database. PHPinfo reports presence of mysqli.
Does anyone have any ideas about this problem?
david
--
40 yrs navigating and computing in blue waters.
English Owner & Captain of British Registered 60' bluewater Ketch S/V Taurus.
Currently in San Diego, CA. Sailing bound for Europe via Panama Canal after
completing engineroom refit.
--- End Message ---
--- Begin Message ---
Vizion wrote:
I am trying to run Fabforce DBDesigner 4.0.5.6 Beta on:
win xp pro Version 2002 Service Pack 2
PHP 5.0.5
Mysql server 5.0.13 installed from 5.0.13-rc-win32.zip
and as Fabforce have closed their forum due to hacker problems I am hoping
someopne here might have some idea how to solve a problem.
I get a 'dbexpress' username/password failure on any attempt by DBDesigner to
connect to a database. PHPinfo reports presence of mysqli.
Does anyone have any ideas about this problem?
david
I think you will need to set up a user account with an old style
password in mysql. It worked for me.
http://dev.mysql.com/doc/refman/5.0/en/old-client.html
--- End Message ---
--- Begin Message ---
Can you use AJAX to output an entire php-generated embed tag into a
web page?
something like:
<?php
// simple no frills qt embed
$qtembed = <<<EOB
<item>
<?xml version="1.0" encoding="UTF-8"?>
<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
height="352" width="216" codebase="http://www.apple.com/qtactivex/
qtplugin.cab">
<embed src="themovie.mov" width="352" height="216">
</embed>
</object>
</item>
EOB;
header('Content-Type: text/xml'); // ajax only seems to like text/xml
header('Content-Length: '.strlen($qtembed));
echo $qtembed;
?>
I am a bit new to Ajax stuff, but thankfully, have been able to make
simple examples work.
From the examples I have tried thus far , it 'appears' that Ajax
only supports sending/receiving elements like zip code....not entire
tags
Is there a way to 'curl' the html to see what 'xmlhttprequest' is
sending and receiving ?
Maybe I am going about this the wrong way and there is a better
solution?
I wanted to avoid pop-up windows, launching new html pages, and
iframes if possible.
Ultimately, I want to dynamically write an invisible movie embed tag
into an html document when called by some 'geturl' actionscript.
Basically, click a button in a flash movie, and the quicktime
player launches.
Instead, should I write a 'empty" quicktime movie tag into the html
document with the element, moviename, for Ajax to target ?
many thanks in advance :)
g
this is the script I was attempting to modify:
http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/
example.html
these are the two javascript functions where loadDoc is called by a
form from the above html
function loadDoc(evt) {
// equalize W3C/IE event models to get event object
evt = (evt) ? evt : ((window.event) ? window.event : null);
if (evt) {
// equalize W3C/IE models to get event target reference
var elem = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);
if (elem) {
try {
if (elem.selectedIndex > 0) {
loadXMLDoc(elem.options[elem.selectedIndex].value);
}
}
catch(e) {
var msg = (typeof e == "string") ? e :
((e.message) ? e.message : "Unknown Error");
alert("Unable to get XML data:\n" + msg);
return;
}
}
}
}
// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
var result = "";
if (prefix && isIE) {
// IE/Windows way of handling namespaces
result = parentElem.getElementsByTagName(prefix + ":" +
local)[index];
} else {
// the namespace versions of this method
// (getElementsByTagNameNS()) operate
// differently in Safari and Mozilla, but both
// return value with just local name, provided
// there aren't conflicts with non-namespace element
// names
result = parentElem.getElementsByTagName(local)[index];
}
if (result) {
// get text, accounting for possible
// whitespace (carriage return) text nodes
if (result.childNodes.length > 1) {
return result.childNodes[1].nodeValue;
} else {
return result.firstChild.nodeValue;
}
} else {
return "n/a";
}
}
--- End Message ---
--- Begin Message ---
> Can you use AJAX to output an entire php-generated
> embed tag into a web page?
You could use XMLHttpRequest's responseText property with innerHTML,
which is probably easier than using XML.
--- End Message ---
--- Begin Message ---
Does eval() have a synonym?
I store html in a mysql record, extract it into $contents. Under normal
circumstances, I have to eval($contents) to get any embedded php code to
work.
But when I use FCKeditor:
http://testesp.flsh.usherb.ca/~johj2201/ramtest.php
$contents='<input type="text" value="<?php echo "hello world"; ?>';
$oFCKeditor->Value = $contents;
$oFCKeditor->Create() ;
Somehow FCKeditor eval()s $content. Under normal circumstances, I would
ask the FCKeditor forum to address this. I would if I could point out to
them the bug. But I cannot find any instances of eval().
Does eval() have a synonym? Or can I un-eval($contents)?
John
--- End Message ---
--- Begin Message ---
John Taylor-Johnston wrote:
Does eval() have a synonym?
I don't usually like to answer a question with a question, but consider
this:
eval($code);
This produces the following output:
red
Given this, what was the value of $code?
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--- End Message ---
--- Begin Message ---
On Sun, 2005-10-30 at 21:15, Chris Shiflett wrote:
> John Taylor-Johnston wrote:
> > Does eval() have a synonym?
>
> I don't usually like to answer a question with a question, but consider
> this:
>
> eval($code);
>
> This produces the following output:
>
> red
>
> Given this, what was the value of $code?
The infinite set of source code permutations that can output the word
'red' as a sole output regardless of whatever other logic may occur
within the content of $code. I use 'can output' because the particular
evaluation may not always output 'red' since the above example may be an
isolated case that occurs once every trillion runs or so and we just
happened to hit it :B
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
I guess I won the powerball $100 million. I'd feel better with the cash ;)
John
Robert Cummings wrote:
Does eval() have a synonym?
The infinite set of source code permutations that can output the word
'red' as a sole output regardless of whatever other logic may occur
within the content of $code. I use 'can output' because the particular
evaluation may not always output 'red' since the above example may be an
isolated case that occurs once every trillion runs or so and we just
happened to hit it :B
--- End Message ---
--- Begin Message ---
I need to generate embedded php within in a mysql record. $contents is
the actual contents of that record.
<?php
$contents = "<div class=\"indent\" style=\"font-size: 16px; font-family:
arial,helvetica; font-weight: bold;\">About the Project</div>
<?php echo \"hello world\"; ?>";
echo eval($contents);
?>
I get this error:
Parse error: parse error in /var/www/html2/test.php(4) : eval()'d code
on line 1
If I just echo $contents, my browser spits out:
<div class="indent" style="font-size: 16px; font-family:
arial,helvetica; font-weight: bold;">About the Project</div>
<?php echo "hello world"; ?>
What's wrong? eval() is the correct thing to do, I thought?
--- End Message ---
--- Begin Message ---
On Sun, 2005-10-30 at 21:16 -0500, John Taylor-Johnston wrote:
> I need to generate embedded php within in a mysql record. $contents is
> the actual contents of that record.
>
> <?php
> $contents = "<div class=\"indent\" style=\"font-size: 16px; font-family:
> arial,helvetica; font-weight: bold;\">About the Project</div>
> <?php echo \"hello world\"; ?>";
> echo eval($contents);
> ?>
>
> I get this error:
> Parse error: parse error in /var/www/html2/test.php(4) : eval()'d code
> on line 1
>
> If I just echo $contents, my browser spits out:
>
> <div class="indent" style="font-size: 16px; font-family:
> arial,helvetica; font-weight: bold;">About the Project</div>
> <?php echo "hello world"; ?>
>
> What's wrong? eval() is the correct thing to do, I thought?
>
eval() expects PHP code, not HTML with embedded PHP code. Try this
(untested):
eval( " ?> $contents <?php " );
--
Jasper Bryant-Greene
General Manager
Album Limited
e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand
--- End Message ---
--- Begin Message ---
<?php
$contents = "<div class=\"indent\" style=\"font-size: 16px; font-family:
arial,helvetica; font-weight: bold;\">About the Project</div>
<?php echo \"hello world\"; ?>";
echo eval($contents);
?>
eval() expects PHP code, not HTML with embedded PHP code. Try this
(untested):
eval( " ?> $contents <?php " );
Scary. But it works.
Shouldn't that error because of the unexpected ?> and <?php in a bigger
example?
John
--- End Message ---
--- Begin Message ---
On Sun, 2005-10-30 at 21:24 -0500, John Taylor-Johnston wrote:
> <?php
>
> >>$contents = "<div class=\"indent\" style=\"font-size: 16px; font-family:
> >>arial,helvetica; font-weight: bold;\">About the Project</div>
> >><?php echo \"hello world\"; ?>";
> >>echo eval($contents);
> >>?>
> >>eval() expects PHP code, not HTML with embedded PHP code. Try this
> >>(untested):
> >>
> >>eval( " ?> $contents <?php " );
> >>
> Scary. But it works.
> Shouldn't that error because of the unexpected ?> and <?php in a bigger
> example?
No, because eval(), when passed string $str, effectively does this
silently:
$str = "<?php " . $str . " ?>";
and then passes $str to the PHP interpreter.
Which is, in most cases, what you want, because you want to evaluate PHP
code.
However, if eval() is the answer, you're probably asking the wrong
question. You should take a hard look at your code and think of a better
way to do what you need to do.
I can assure you one does exist, but with your example it's fairly
obvious, so you'd need to explain better what you're trying to do before
I could help you.
--
Jasper Bryant-Greene
General Manager
Album Limited
e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand
--- End Message ---
--- Begin Message ---
eval( " ?> $contents <?php " );
However, if eval() is the answer, you're probably asking the wrong
question. You should take a hard look at your code and think of a better
way to do what you need to do.
Back to the drawing board? It is either store my html+embedded code in a
mysql record, or in an html file, which means playing with fopen. It's
easier to hand tweak in phpmyadmin.
Nonetheless, even though your test code worked (thanks!) this doesn't. Sigh.
if ($contents = displaynew()) eval( " ?> $contents <?php " );
function displaynew()
{
$file = basename($_SERVER['PHP_SELF']);
require 'connect.inc';
$sql = "SELECT HTML FROM `$db`.`$table_editor` WHERE `Filename` LIKE
'".addslashes($file)."' LIMIT 1;";
if ($myquery = mysql_query($sql) and mysql_num_rows($myquery) > 0) {
$mydata = mysql_fetch_array($myquery, MYSQL_NUM);
return $mydata[0];
}
return false;
}
--- End Message ---
--- Begin Message ---
On Sun, October 30, 2005 8:51 pm, John Taylor-Johnston wrote:
> eval( " ?> $contents <?php " );
>
>>However, if eval() is the answer, you're probably asking the wrong
>>question. You should take a hard look at your code and think of a
>> better
>>way to do what you need to do.
>>
>>
> Back to the drawing board? It is either store my html+embedded code in
> a
> mysql record, or in an html file, which means playing with fopen. It's
> easier to hand tweak in phpmyadmin.
> Nonetheless, even though your test code worked (thanks!) this doesn't.
> Sigh.
>
> if ($contents = displaynew()){
echo "CONTENTS:<pre>", htmlentities($contents), "</pre>\n";
eval( " ?> $contents <?php " );
}
I'm guessing $contents ain't what you think.
>
> function displaynew()
> {
> $file = basename($_SERVER['PHP_SELF']);
> require 'connect.inc';
> $sql = "SELECT HTML FROM `$db`.`$table_editor` WHERE `Filename`
> LIKE
> '".addslashes($file)."' LIMIT 1;";
> if ($myquery = mysql_query($sql) and mysql_num_rows($myquery) > 0)
This 'and' should probably be '&&' ...
Though I never really used 'and' enough to know for sure.
At any rate, you've got *NO* error-checking for an invalid query here.
> {
> $mydata = mysql_fetch_array($myquery, MYSQL_NUM);
> return $mydata[0];
> }
> return false;
> }
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---