
timbrown
Members-
Posts
35 -
Joined
-
Last visited
Never
Everything posted by timbrown
-
Hey thanks Orio, I missed your post while I was typing. Works lovely! Thanks very much. Tim.
-
Thanks, I thought of using regular expressions like this but unfortunately this regular expression also replaces the character before the comma so you end up with "something" instead of "something1".
-
Thanks for the reply. I think that with your suggestion if the user included the characters ',' in the string then it would cause an undesired split. I was thinking there might be a way of escaping commas like this - something1,something2,1\,2\,3 but I cant figure out how to split only on the non-escaped commas. by the way, the string is coming from GROUP_CONCAT in mysql.
-
Hello, This has been causing me grief for hours! I have a string like this - "'something1','something2','1,2,3'" I want to split or explode at the commas, without exploding the 1,2,3 part. The values are user input so in fact could contain any characters. Thanks!
-
Hello, I though I had fixed this one but oh no! something.xml <app> <id>app1</id> </app> something.xsl <xsl:template match="app"> <div><xsl:apply-templates/></div> </xsl:template> <xsl:template match="id"> <xsl:attribute name="id"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> in IE this outputs something like - <div id="app1"></div> but when I use php XSLTProcessor I get the message - "Cannot add attributes to an element if children have already been added to the element". Help! I have been struggling with this...
-
Sorry! Fixed it myself by putting the attribute line inside the app template.
-
Hi, ??? I am trying to use phps tranformToXML function. I can get it to work ok but I am having problems adding attributes. example: something.xml <app> <id>app1</id> <title>a title</title> <content>some content</content> </app> something.xsl <xsl:template match="id"> <xsl:attribute name="id"> <xsl:value-of select="."> </xsl:attribute> </xsl:template> <xsl:template match="app"> <div> <xsl:apply-templates/> </div> </xsl:template> the idea of this is to create an attribute within "app" called "id" and give it the value of the "id" element within the xml file. this works fine when just linking the stylesheet to the xml file and displaying it in a browser, but when I try to put the files through transformToXML I get an error like - "Cannot add attributes to an element if children have already been added to the element" I have tried moving things around to no avail. Any ideas? Tim.
-
Yeah I suppose I wouldn't save that much code, just trying to keep things neat and orderly. There are ways to achieve what I want, but I would prefer to just have an include. p.s. I tried reporting this as a bug but it isn't.
-
Thanks, If YOU might not be understanding the docs, what chance does that give me!?!?! I will try and file a bug report and see how far I get. Thanks for all the help, Tim.
-
Yes it does. Sorry but what your describing does not make sense. This will work as expected. inc.php <?php function foo() { return FALSE; } ?> index.php <?php include 'inc.php'; if (!foo()) { echo 'foo() returned false'; } ?> That's because in my scenario the include is within the function. This "return" does not end execution of the function - includefile.inc <?php echo __FUNCTION__; return false; ?> index.php <?php function(){ include("includefile.inc"); echo "hello"; } ?> I want to be able to reuse includefile.inc in several methods.
-
__FUNCTION__ seems to work fine from within a method. From the php manual - If called from within a function, the return() statement immediately ends execution of the current function... This does not seem to apply when using include() and also eval(). I suppose this is because eval() it is not actually being called from within a function. Any other ideas?
-
This is literally what i'm trying to do - function validate(){ // this bit of code I want to reuse in several functions $this->log[] = __FUNCTION__.": an error occurred"; return false; } This works fine, but once I put it into an include file, __FUNCTION__ does not work at all and return does not halt the function and return false as I would expect.
-
Thanks for getting back to me. Is there an alternative to include(), one that is compiled & evaluated at the same time as the rest of the code?
-
Hi, I am trying to reuse code using include files. I understand that the files are evaluated seperatley from the rest of the code. The problem I am having is that when I use return, it does not affect the containing document, only the included one. example: in this case the echo is not called because of the return: return false; echo "hello"; in this case the echo is called because the return is in the include: "includeFile.inc": return false; container file: require("includeFile.inc"); echo "hello"; Is there any way round this functionality? I would like to be able to just put code into a text file and have it reused in the normal flow of the code. Thanks in advance, Tim.
-
just so my various classes can share function code.
-
ok, you might have a function in an include file like this - thefunction.inc function functionName(){ some code... } and I want to include that function in a class definition as a method like this - class className { public someVar = ""; public someVar = ""; public someVar = ""; // defining a method normally function someFunction(){ some code... } // define one using the include include("thefunction.inc"); } this doesn't work because php is expecting a function, not an include.
-
Hi there, Is there a way of using an include to define a method in a class?
-
thanks anyway! Tim.
-
so the function only exists in the definition and there is no way of holding it in the object?
-
my files are like this- file1 <?php class MyClass { public $thing = "abcdefg"; function tester(){ echo "tester has been called!"; } } session_start(); $x = new MyClass; $_SESSION["testvar"] = $x; $_SESSION["testvar"]->tester(); ?> file 2 <?php session_start(); $_SESSION["testvar"]->tester(); ?>
-
thanks, but I still get that error when calling the function from a second file if it does not include the class definition.
-
Hi, I am storing an object in a session variable, but when I call a function of that object I get the following message - The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "MyClass" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Documents and Settings\Tim Brown\My Documents\Portal\v4\test\test.php on line 4 I don't really want to include the class definition in the code from which the function is called.
-
Excellent! that did the job nicely. Thanks.
-
thanks I'll try.
-
Hi, I want to output the name of a function from within the function. this doesn't work but something like this would be nice - function tester(){ echo $this.function_name; } even better would be object + function reference in one. any ideas?