Re: [PHP] str_replace() problem
Just change the order and do the "search and replace" on "Blueberry" before doing it on "Blue." Ei: str_replace("Blueberry","Strawberry",$paragraph); str_replace("Blue","Red",$paragraph); or: str_replace(array("Blueberry", "Blue"), array("Strawberry", "Red"), $paragraph); _ Marcus Rasmussen [EMAIL PROTECTED] www.marcusr.dk - On 31-03-2003 at 13:52 René Fournier wrote: - I am performing a str_replace() on a large string, and everything works fine, except that two of the elements I'm searching for (and replacing) have the same first letters. To keep it the issue clear, here's a simple example of what I'm talking about: Blue Blueberry Now, if I use: str_replace("Blue","Red",$paragraph); str_replace("Blueberry","Strawberry",$paragraph); ...all occurrences of Blueincluding Blueberrywill be replaced with Red. The result will be something like: Red Redberry ...But what I want is... Red Strawberry I need str_replace to somehow only search for a complete occurrence of each item. How do I do that? I've read the docs, and I just can't see any examples. Thanks. ...Rene --- René Fournier, [EMAIL PROTECTED] Toll-free +1.888.886.2754 Tel +1.403.291.3601 Fax +1.403.250.5228 www.smartslitters.com SmartSlitters International #33, 1339 - 40th Ave NE Calgary AB T2E 8N6 Canada -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global var.
Putting an & sign in front of the $id in the first line should do the trick: $variable = &$id; A short example: $bar = 0; $foo = &$bar; $bar = 2; print $foo; //prints 2 ______ Marcus Rasmussen [EMAIL PROTECTED] www.marcusr.dk - On 31-03-2003 at 19:56 Sebastian wrote: - hello all, $variable = $id; // some other stuff @mysql_query here $id = mysql_insert_id(); to the question: How do I get $id from insert_id() to pass to $variable above? Hard to explain the situation i am in, but the query has to be below $variable, is it possible to 'globalize' $id so it passes to the top $variable? first time i ever ran into this problem. Thanks in advanced. cheers, - Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] parse_str()
This should work: parse_str($example_string, $_GET); ___ Marcus Rasmussen [EMAIL PROTECTED] www.marcusr.dk - On 01-04-2003 at 03:20 Jose wrote: - > I might be wrong here, but with the code below I would expect $_GET to be > filled and the script to output the next line: > >$example_string = 'action=kick&item=me'; >parse_str($example_string); >var_dump($_GET); >?> > > // expected output: > // > // array(2) { ["action"]=> string(4) "kick" ["item"]=> string(2) "me" } > // Forgot to mention what I get. // actual output: // // array(0) { } > Is my assumption wrong? What would be the workaround? > > Thanks, > > Jose > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I detect if mysql_connect failes?
Hello. My question is: How do I detect if mysql_connect() failed when I'm surpressing the error message with @ like $linkid = @mysql_connect("host","user","pass"); And how do I, if it failes, get the error message? The manuel says that it: [quote]Returns a positive MySQL link identifier on success, or an error message on failure.[unquote] In my mind I should be able to detect if it returns an errormessage like this: if(!$linkid) $error = mysql_error(); or: if(!is_int($linkid)) $error = mysql_error(); Noone of theese 2 types works :-(. I'm using is_int() because the manuel says that mysql_connect() returns an int. (How can it then return an error message? I thought that an error message would be some kind if string :-).) Here comes another problem, when an error occours I should be able to see the message with mysql_error() (since the linkid not contains an error message.) Marcus R.
Re: [PHP] How do I detect if mysql_connect failes?
I CAN detect if an erro occours. (just some error I did) I still don't get any return from mysql_errno() or mysql_error() I don't iether get a return from mysql_errno() or mysql_error() when I do not surpress with @ (the function, mysql_connect(), then prints a message.) Guess I could surpress and write the error message myself, but I just want the original one, wich I should be able to get with mysql_error() PS. It is only mysql_connect that do it. Marcus R. *** REPLY SEPARATOR *** On 20-04-01 at 12:35 David Robley wrote: >On Fri, 20 Apr 2001 12:19, Marcus Rasmussen wrote: >> Hello. >> >> My question is: >> How do I detect if mysql_connect() failed when I'm surpressing the >> error message with @ like $linkid = >> @mysql_connect("host","user","pass"); >> And how do I, if it failes, get the error message? >> >> The manuel says that it: >> [quote]Returns a positive MySQL link identifier on success, or an error >> message on failure.[unquote] >> >> In my mind I should be able to detect if it returns an errormessage >> like this: if(!$linkid) >> $error = mysql_error(); >> or: >> if(!is_int($linkid)) >> $error = mysql_error(); >> Noone of theese 2 types works :-(. >> I'm using is_int() because the manuel says that mysql_connect() returns >> an int. (How can it then return an error message? I thought that an >> error message would be some kind if string :-).) >> >> Here comes another problem, when an error occours I should be able to >> see the message with mysql_error() (since the linkid not contains an >> error message.) >> >> Marcus R. > >Try testing the value of mysql_errno() and echo mysql_error accordingly. > >-- >David Robley| WEBMASTER & Mail List Admin >RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ >AusEinet| http://auseinet.flinders.edu.au/ >Flinders University, ADELAIDE, SOUTH AUSTRALIA > >-- >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] Arrays in forms {?!}
1) The example you have shown should work. Take a look at the foreach controle structure. (Link at bottom of mail.) 2) You cannot assign a value to a checkbox. It can only be set by the "checked" keyword (ie: .) 3) The value of a checked checkbox is "on". If a checkbox is not checked it will not be passed to you by the clients browser. So if you where wondering why you could not get the value of some of the checkboxes, then that was why. 4) If you don't have to give the user a more thorough description then why not make a multiselect select box instead. Example on a multiselect selectedbox desc desc ... The above selectbox will display 20 rows in the box and if there is more than 20 selections you will be able to scroll it. You can get more information at: http://www.php.net/manual/en/control-structures.foreach.php http://www.php.net/manual/en/language.variables.external.php _____ Marcus Rasmussen - On 24-04-02 at 15:19 Liam MacKenzie wrote: - >Hi all, > >I have a form, with about 40 checkboxes, I want to write a PHP document >that >processes the submission and displays the values of the checkboxes that >were >checked. >Pretty basic stuff, I've tried a few different things, some work but >display >"Array" at the top of the list of values. > > > > > > >Counter-Strike > > > >Total Annihilation > > > > > > >while ( $element = each( $games ) ) >{ > echo $element["value"]; > echo ""; >} > > > > >I tried this too, it gave the same results as the above... > > > >if (is_array($games)) { > for ($z=0;$z echo "$games[$z]"; > } >} >else { > echo "$games"; >} > > >I'm missing something real stupid, please help me out > >Thanks, >Liam > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] SQL Question
You could do it this way WHERE column LIKE 's%' ORDER BY column Now you'll get all rows sorted and where column is staring with an 's' or 'S' - On 28-03-02 at 17:30 Sebastian A. wrote: - >When you say "ORDER BY that", is it also possible to do that via letters >such as ORDER BY 'S', because from what I understand, ORDER BY has to be a >column. > >-Original Message- >From: Jason Wong [mailto:[EMAIL PROTECTED]] >Sent: Thursday, March 28, 2002 3:49 PM >To: [EMAIL PROTECTED] >Subject: Re: [PHP] SQL Question > >On Thursday 28 March 2002 22:34, Sebastian A. wrote: >> How do I sort out data from mysql_fetch_row() or mysql_fetch_array? For >> example say I wanted to list all my users alphabetically. How would I do >> this? Or say I had a form and I wanted to present the content to the user >> *AFTER* they have filled it out so that they can check for mistakes. >> Mysql_fetch_row() returns all the rows in a field, so I would guess that >I >> have to sort using PHP. Can anyone provide me with an idea as to how I >> could accomplish this? > >1) This type of question should best be posted to the php-db list. > >2) Sorting should best be done from mysql using the ORDER BY clause: > > SELECT this, that, the, other >FROM table > ORDER BY that > >3) If you insist on sorting in PHP then read all the rows from your query >into an array and use one of the array sort functions -- asort() etc. > > > >-- >Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > >/* >Things are more like they used to be than they are now. >*/ > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating variable names 'on the fly'
You can allso do like this: $i = 1; ${"test". $i} = "123"; echo $test1; _______ Marcus Rasmussen [EMAIL PROTECTED] On 21-09-01 at 11:21 _lallous wrote: >you can always use eval to create a variable too! > >$i = 1; >eval("\$test$i=123;"); >echo $test1; >?> > >"Neil Freeman" <[EMAIL PROTECTED]> wrote in message >[EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >> Hi there, >> >> How do I generate variable names 'on the fly'? I wish to have variable >> names along the lines of $genre_category_1, $genre_category_2, >> $genre_category_3 etc. >> >> Ideally it would be along the lines of this... >> >> ### >> $current_field_number = 1; >> $genre_number_fields = 7; >> >> while ($current_field_number < $genre_number_fields) >> { >> //this var will change on every loop >> $genre_desc = $db_movies_genres->Record[$current_field_number]; >> >> //something along the lines of...(you get the idea) >> $str_category = "genre_category_" . $current_field_number; >> $$str_category = $genre_desc; >> >> $current_field_number++; >> } >> ### >> >> Any help would be greatly appreciated. >> >> Neil >> >> Email: [EMAIL PROTECTED] >> [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 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] help with classes
You can allso do this: //foo.class.php class Foo{ var $bar; function Foo($bar){ $this->bar = $bar; } } //foo.php include("foo.class.php"); $bar = "1234"; $foo = new Foo($bar); //Now: $foo->bar = "1234" Regards: Marcus Rasmussen *** REPLY SEPARATOR *** On 14-02-2001 at 15:52 Joseph H Blythe wrote: >On Mon, 12 Feb 2001 21:04:30 -0800 >Joe wrote: > >JC> Is this closer to what you were looking for? >JC> - Joe >JC> >JC> JC> >JC> class Foo { >JC> >JC> var $bar; >JC> >JC> function mymethod(){ >JC> >JC> global $foo; >JC> $this->bar = $foo; >JC> >JC> } >JC> >JC> } >JC> >JC> $foo = "hello world"; >JC> >JC> echo ""; >JC> >JC> $cls = new foo(); >JC> $cls->mymethod(); >JC> echo $cls->bar; >JC> >JC> echo ""; >JC> ?> >JC> > >hmm sort of is, basically this works: > >// Foo.class.php >class Foo { > >var $bar; > >setBar($bar) { > $this->bar = $bar; >} > >} > >// foo.php >include("Foo.class.php"); >$foo = new Foo; >$bar = "1234567789"; >$foo->setBar($bar); > >Regards, > >Joseph > >-- >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]