Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Change Alternate Commas To Semi Colons...


With a string of authors such as:

I would like to write a function to change every other comma into a
semi colon (thereby defining where one name ends and the next begins).

I could do it by writing a complex (and slow) procedure - but is there
a quick way of doing it using regular expressions, for example?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Generating Semi-dynamic Pages?
I set up my index page and a couple of others as semi dynamic pages like he suggested in the advanced php section of his tutorial. Anyway everything was working fine until I put an .htaccess file in that folder, it is just a fairly standard .htaccess that password protects the file,

but the trouble is that now when I try to generate a new index page instead of using the path http://localhost/admin/index.php when looking at the template (index.php) which it needs to do for the php on the template to run, it goes to c:/phpdev/www/admin/index.php so as the browser is not used the php is not run and I get a load of code on index.html, I don't think I've explained this that well so I hope the code and comments below help.

This is part of the code used basically is uses $srcurl as a source file then puts into a variable and through fwrite etc it puts it all in a temporay file then finally writes it to index.html.

<!-- generateindex.php -->
<?php
$srcurl = "http://localhost/admin/index.php";
$tempfilename = "tempindex.html";
$targetfilename = "index.html"; ?>

The problem is that with the .htaccess forcing it to use the path on the harddrive rather than the url none of the PHP from the tempate index.php gets converted.

SEMI-OT : Javascript Rich Text Editor
I'm looking for a javascript-based rich text/wysiwyg html editor that can be
easily integrated in a php cms. I don't require any advanced features
(tables, images etc) , just basic text formatting.


OOP Database Tables <-> Php Interface (semi LONG)
I'm trying to grasp OOP to build an interface using class objects that lets
me access database tables easily. You have probably seen this before, or
maybe even built it yourself at some point in time. I have studied some
examples I found on the internet, and am now trying to build my own from
scratch.

I have made a default table class (DB_Table), a default validation class
(Validator) which is an object inside DB_Table and my final database tables
each get a class: e.g. User, UserProfile, Country, etc that extend the
DB_Table class.

Its something along the lines of (incomplete code, just for demonstration
purpose):

<?php

class DB_Table
{
public function __construct()
{
// intialize object
// initialize (common) validator
$this->validator = new Validator( $this );
}

public function loadData()
{
// get all data from record
}

public function saveData()
{
// save all data to record
}

public function __get( $field )
{
// get object property
}

public function __set( $field, $value )
{
// set object property
}
}

class User extends DB_Table
{
public $dbt = DB_TABLE_USER;

public $fields = array(
'id' =NULL,
'userType' =NULL,
'username' =NULL,
'password' =NULL,
'email' =NULL,
'active' =NULL,
'timeCreated' =NULL,
'timeActivated' =NULL,
'timeUpdated' =NULL
);

public $fieldSpecs = array(
'id' =array(
'screenname' ='user id',
'type' ='int',
'autoinsert' =true,
'autoincrement' =true,
'static' =true
),
'userType' =array(
'type' ='tyniint',
'nodisplay' =true
),
'username' =array(
'screenname' ='username',
'type' ='string',
'unique' =true,
'required' =true,
'static' =true,
),
// etc...
);
}

?>

It definately still needs a lot of tayloring for it to even work smoothly
for straightforward DB tables. But besides that, a few future issues are
bothering me already:

For instance, take the class User: let's say somebody registers at my site.
This person fills in the details. The Validator class checks each field
seperately. No problem. A new User record is inserted in the database.

But what now, if a user wants to login to the system after the user is
registrated?
I would create an instance of class User. Asign the credential values to the
object. And let the Validator class do its work again.
But, if a user logs in with incorrect credentials, I don't want to report
back to the user whether he/she filled in an incorrect username or an
incorrect password. No, I only want to report back that he/she has filled in
wrong credentials.

But the Validator class only checks each field seperately. In order to keep
the Validator class as common as possible would you build a seperate Login
class for instance? A class that has some custom validation methods? Or
perhaps just insert custom validation methods in the User class? I myself
just cannot seem to make up my mind in this case. Probably cause I'm still
too inexperienced when it comes to OOP programming.

A few other minor questions come to mind also:
- My gut feeling tells me it is wise to make a reference to the Validator
class inside DB_Table, e.g:
$this->validator =& new Validator( $this );
.... because it only creates a single instance of the object, right?

- And why can't I refer to a private variable in DB_Table from an extended
class (such as User)? I would asume, that this private variable, declared in
the parent object, is now a private variable in User also, no?

- And last but not least, is there a way for me to access let's say User
properties from the Validator class without having to pass $this as an
argument to:
$this->validator = new Validator( $this );
.... I know the following to be incorrect, but I was thinking of something
like the keyword parent.

Alternate For Odbc_num_rows?
I'm trying to do a SELECT * FROM statement on my database and finding out how many rows are affected by the query using odbc_num_rows().

Unforunately It always returns -1 because of my driver I guess. This seems to be normal operation for some drivers according to the documentation on zend.com.
"Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers."

So does anyone have a suggestion on how I can accomplish the same task without using odbc_num_rows() to find how many rows were affected by my query?

Alternate Location For Php.ini
Is there a way to set php.ini to the alternate location?

I'm trying to use 2 version of PHP(php4 and php5), but php.ini is in the
way. Anyone knows how to circumvent this issues? Perhaps there is an env
variable we can set.

How Do You Make Something Alternate...
I'm using the while() function to get posts out of a database, they are each in their own table, and I want the tables to alternate from $color1 to $color2 like this forum does when reading a thread on all the posts, how can I do this?

Commas
Hi everyone, I would like to be able to insert commas into a number every three spots. Like if I had 1728, a comma would be insert between the 1 and 7. The number is random so I need to know if there is a works-for-all-numbers.

Commas In CSV
I have built this form in php and when I click on it, I am storing all the fields in .csv file. There is one field known as address which can contatin commas How can I make it so that when I open it in excel address remains below address as in the commas submitted for address in the form becomes part of the address.

Commas In #'s
ok i want to put commas in #'s like 3,000,000,000 ok. ok say the number is $player[gold] and say that it is 3000000 how do i add commas?

Display Alternate Colors For Each Row
I wrote a code to display some values taken from text file in the webpage. I am using a function to display alternate colors for each row. I am getting breaks at the end of each column which I should not get. Code:

Print Alternate Rows
the below code will return information from a mysql table. The page that the results will be displayed on is divided in two colums. how do I get the results to print in alternate rows. So the record one goes to column one record two goes to column two record three goes to column 1 and so on Code:

Add Commas Between Names
i've got a script that pulls first name, last name, and suffix from a DB query and echos them only if they are not null. the names are cross-referenced by id number from two other tables. it displays the name pieces that are not null for each "job", and the jobs and names are determined by another id number for an individual issue page. an example of the output is here: Code:

Getting Rid Of Inverted Commas
If someone types 'Tom's Photos' into a input field i need a piece of code that removes the " ' " when the information is processed.

Example
Tom's PhotosScript Processes InformationScript Finds the " ' " in Tom'sScript Removes " ' " in Tom'sResult Is Toms.

PhpMyAdmin - Pass Alternate Host Through URL?
I just set up php on my computer, and I need to be able to connect to remote hosts frequently. Is there a way to pass index.php3 variables that will tell the program to go to a different host, use a variable user and password?

I've been playing with the code, but I figure there's got to be a way to do it, and I don't want to mess up the code...

Multiple Rows And Alternate Color
Below I found a code to make multiple colums from the output of a DB, how
can I incorporate alternat colors to the multiple row snippet?

<?php
//set the number of columns
$columns = 2;
mysql_connect('localhost','','');
mysql_select_db('test');
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<TABLE BORDER="0">";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>";
}
echo "<TD>" . $row['stuff'] . "</TD>";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>";
}
}
echo "</TABLE>";
?>

Fetching Just Links From Alternate Pages
I have a content fetching script designed. Now, the fetched content is in a variable called $Result. Now, is there any way so that I could just take all of the <a href(*.)</a> information, and possbly place it inot a variable.

Display Alternate Image If Other Not Found
I'm trying to display an alternate image and its been giving me a problem . I'll try and explain

If there is an image file found in the table image_files then i want it to be displayed and if there is no image found for that child then I want the blank image to display.  If the child is a registered member then  a link will be attached to the image and if the child is not a member then no link will be attached to the image.

The below code displays the image if one is found but if no image is not found the blank image is not being displayed.  I believe it has something to do with my if statements.

-------------
if the child_id is found in the column familyMembers_id from the table image_files then there is an image for that child if the child_id is not found then there no image and the blank image should be displayed. Code:

Alternate Ways To Pass Information To Scripts
This is one for the PHP-ilk that can sneeze better code than most write. Under Apache, and only under Apache, you can use the following snippet of code to get information passed to the script in a way other than get/post/sessions, which is passed directly after the script name but before the querystring, eg:

http://blah.net/index.php/type/value/type/value/?type=value
PHP Code:

Inserting Proper Commas Into An Integer
I've looked and looked, and I can't find anything about this, and it's driving me nuts! All I want to do is insert a comma into a long number (when applicable) to make the display look nicer. This script is counting pageviews on my site, so it'll be a large ugly number in a few days.

For example, instead of displaying:

1876235

I would want it to display

1,876,235

The integer could be any size (potentially), but I don't see any need to worry about numbers beyond 8 digits. Any suggestions?

Regular Expression, Exclude Commas
Greetings all. I'm a newbie, desperate to learn, and I've searched here and Google for such things as "PHP regular expression comma" and variations on that theme, but I haven't been able to figure out what I'm doing wrong, though I've visted several sites and tutorials dealing with regular expressions.

I've got a form on my bosses' Web site where a customer can enter a price range and get a list of our "stuff" that falls within that price range. I'd like to set something up so that if they enter letters or commas or anything other than numerals in the price range form fields, they'll be gently encouraged to go back and do it right. :)

This is what I've got for the time being:

if (!eregi('^[0-9]', $pricemin) ¦¦!eregi('^[0-9]', $pricemax)) {
echo '<P>You have not entered a valid price range. '
echo 'Be sure to enter only numbers, and no letters or punctuation marks, when searching for a price range. '
echo 'Click the Back button on your browser to search again.'
exit;
}

This works, insofar as if someone types "blah" in the pricemin or the pricemax form field, they'll get the message. But if some well meaning person types "50,000" or "$50,000" instead of "50000" in there, they currently get a MySQL error. I've got a note telling people not to use letters or punctuation, but you know how people are.

All the tutorials I've seen talk about including or excluding different characters based on different criteria, but everything I've tried to put a comma in there has failed and/or messed up the query somehow. What am I missing?

Stripping Commas From Real Numbers
I have an HTML form in a PHP script which queries the user for a dollar amount of sales.
If a user enters "1,000,000" rather than "1000000" for 1 million, PHP (or MySQL?) treats the commas as a decimal and "1" is entered in the database.

A simple work-around is to simply advise the user "Please enter numbers only, no commas or $'s" but this seems awkward. Is there a built in function or another easy way to have commas and currency signs stripped out of form-entered data?

Printing Numbers With Commas Every Third Digit
how do you print numbers with commas every third digit?

like this: 1234567 to this: 1,234,567

Stop The Commas!!! ( Or Knowing When You're At The End Of An Array )
I am looking for a good way to know when I am at the end of a
comma-separated list of array values.

My code is simple (as well as I'm sure is the solution I'm looking for;
and YES I've search the php manual!! Arrggghh! )

Anyway the code goes like this:

...

<td><select name="pref_cities[]" multiple size="6">

<option>Nagpur</option>

<option>Mumbai</option>

<option>Bangalore</option>

<option>Chennai</option>

<option>Kolkatta</option>

</select></td>

...

<?php

$cities = $_POST['pref_cities'];

foreach ($cities as $city) {
echo $city . ", ";
}
?>

I want to know when I'm at the last element in $cities[] so that I can
output a period (.) instead of a comma (,).

Adding Commas To Large Numbers
I have a search that when you search it shows how many results you are being shown and usually the number is between 100,000 and a 1,000,000 how can i add commas to a number for example: 989725?

Strip Out Commas And Characters In A Text Box
I have a form that the user can enter a number in the text field and a calculation is then preformed with PHP when the form is submitted.

$amount = $_POST['amount'];

<input type="text" name="amount" size="20" value="">

Any way to strip out commas and any characters that may be entered. I would like an entry like $5000, 5000, 5,000 and $5,000 all to be passed on to the PHP script as 5000. The way it is now the php math script treats 5,000 as a 5 and $5000 as a 0.

Selecting Alternate Master Dictionary With Pspell Functions
Is it possible to select an alternate master dictionary when using the
pspell interface? There is a way to select a personal dictionary
(pspell_config_personal()), but that is used IN ADDITION to the default
master dictionary, which is not what I want.

I have a different English dictionary I wish to use, and I do not want
to use the default dictionary at all. However, I do not wish to mess
with the existing installation of aspell on the machine by removing the
dictionaries in place.

From the command line I can just do:

aspell --master mydict.rws

but there seems to be no way to simulate the "--master" argument using
the PHP interface. Likewise there seems to be no way to provide the
"--size" argument.

On a related note, are there any examples anywhere of how the 'jargon'
parameter might actually be used? In every example I can find it is
blank, and all references to it in documentation are elliptical at best.

I know I can do all this by piping to the aspell binary but with the
volume of text I'm looking at that's going to be really really slow.

Make A "semi-unique" Hit Counter
Let me explain. I put something like addToCounter();

in my INDEX page. Problem is, counter increments each time the same visitor opens/refreshes the index page. What aproach should I use so that if a visitor opens the index page, browses the site, and goes back to index page, it doesn't count anymore. But when he closes browser/goes to another site, then goes back to my site (index page), it counts again. I've tried sessions in the index page

if (!isset($_SESSION["loggedIn"])... {
     $_SESSION["loggedIn"] = true;
     addToCounter();
}

but doesn't work (or am i doing it wrong?).

Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?

It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.

Pagination & Sort By Stationary Column Header & Alternate Row Colors
Is it possible to have all these features in one mysql data output? I have the sort by column header and alternate row colors....but NO sationary column headers and no pagination.

I've tried to combine each of these features, but I can't get it to work together! Can someone provide an exmple of how this code will look?

My Data Contains Commas And Pipes "¦"
I have some raw data that I was planning to insert into a flat file and then upload/insert into my mySQL DB.

However the data contains commas and pipes "¦". I usually use the ¦ as my delimiter.

Before I upload the data I wanted to remove dupes which happen to be text/blob fields. I usually do this in access.

I thought I could get around this by using quotes as a text qualifier. It didn't seem to work. My other method I usually try is to use some combination of characters like <¦¦> as a delimeter.

However Access only allows one character as a delimeter and phpmyadmin only allows two characters as the delimeter.

How To Change One Page To Change All?
i need to know how to create a page where i only have to change one thing on one page so it changes that text or image on every page of my site. in other words i want to be able to create a template, so if i do want to vchange something in the duture, i only have to change on page, instead of changing each individual page.

Cannot Change Php.ini
System info: PHP Version 4.3.11, Debian, 2.4.18-bf2.4
Configure Command './configure' '--with-ibm-db2=/usr/IBMdb2/V7.1'
'--with-apache=/usr/local/src/EMILLICANWORK/apache/apache/1.3.31'
'--with-gd' '--with-zlib-dir=/usr' '--with-jpeg-dir=/usr/local'
'--with-freetype-dir=/usr/local/src/EMILLICANWORK/apache/work/usr/local'
'--enable-sw_securid' '--with-sybase' '--with-pgsql' '--with-bz2'
'--enable-track-vars' '--enable-bcmath'

Configuration File (php.ini) Path /usr/local/lib

There was not a php file or director in /usr/local/lib, initally I
tried copying the one I had edited in /etc/php4/apache/php.ini. Then
have created the director /usr/local/lib/php, and put the php.ini file
there. Still no change from the default settings to the ones I have
made.

Hello, [XML] Is There Something To Change?
I'm a newbie in XML/XSLT trying to get some HTML output from a simple
XML source that starts with:

QUOTE:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="letter2text.xsl" version="1.0"?>
/QUOTE

I ran phpinfo();
Here is what I gathered:
QUOTE:
libxml
libXML support active
libXML Version 2.6.22
libXML streams enabled

SimpleXML
Simplexml support enabled
Revision $Revision: 1.151.2.10 $
Schema support enabled

xml
XML Support active
XML Namespace Support active
libxml2 Version 2.6.22

xmlreader
XMLReader enabled

xmlwriter
XMLWriter enabled

/QUOTE

The problem is that I keep seeing the XML source in IE6, not the
formatted data.

How Can I Change Every Second Row?
I am making a html table builder, and would like every second row to be
blue. So for that purpose I need a number that changes on every
iteration of a while loop, for exampel so that a value is 0 then 1 then
0 a so forth.

Row Bg Change...
How do you make it so like the first background color of the row is red, then the next one is blue, then red, then blue, based on a bunch of items echo'ed from a db table. ??

How Do I Change A Dir Name?
I just want to know what function i should use for changing a folders name? i have looked at php.net but cant seem to find any function who can you this.

Can You Change A PNG From 8 Bit To 24 Bit Image?
Can you change a PNG from 8 bit to 24 bit image using PHP?

Change The Refferer
I'm looking for a way to change the refferer of the client clicking on
a link to an external site. In other words, the external site should not see where the visitor is coming from, or even better, if i could manipulate the referer so that in their web-server's logs it will show as if they are coming from their own site.

Permission Change
Change permissions to 'file.txt' for be writing by nobody (chmod a+rw). Excuse my ignorance, but what does this mean in english?

How To Change PHP To HTML...
Need to put a small website fully databased (that is 20-30 pages only - mostly pictures) on a CDRom.

Is there a way to automatically do the move or do I have to change everything manually (URL, A tag)?

Change The Standard Out
Is there any way to redirect the standard out to some variable ?

I meen, instead of seending the result to the browser, send it to a
variable.

How To Change Passowrd
I want to change my linux password through PHP script.

Syntax To Change Value
I am trying to change a value but cant quite grasp the syntax
<?
$vtfa=test
$dn=1
?>

<td><?= $vtfa.$dn ?></td>

<? $dn = $dn + 1 ?>
<td><?= $vtfa.$dn ?></td>
<? $dn = $dn + 1 ?>
<td><?= $vtfa.$dn ?></td>

What I want are the three cells to consist of test1, test2 and test3. As you

Any help appreciated



Change Color
Does anyone know how I would make each row of the result a different color:
here is what I have:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<?
$connection=mysql_connect("localhost", "bla bla", "bla bla") or die
("could not connect");
mysql_select_db("yorkbia2_dbname");
$result = mysql_query("SELECT * FROM Board");
echo "<table border=0, table width=200%, bgcolor=#FFFFFF>
";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</tr>
",
$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5],
$myrow[6], $myrow[7], $myrow[8], $myrow[9], $myrow[10]);
}
echo "</table>
";
?>
</body>
</html>

How To Change A File Name
i want to change the name of an uploaded file from:myant.jpg -> to -> ID123.jpg
how do you do it?

what i want is to make a mysql database with pics but i don't want to load the pics on the database. i want to change the name of the picture to a picture_id name (and store the picture info on a table). otherwise i could never load another pic with the same name in a directory.

Layout Change
i made 2 layouts, but i want both of them to be displayed on the same page meaning index.php. Like i dont want layout one on index1.php and layout 2 on index2.php.

I want something like this website http://www.dbgtn.com/, do u see how those people have like 9 layouts and all the layouts appear on index.php page.

Change Case
I want to change the case of the first letter in a word. How would i do this via php? I've looked through the php manual and even searched this forum and i have come up with nothing. I'm sure there's a function.

Php Color Change
I have a form that I have designed with colors. I am using php code to color
it depending upon other values.

On my pc the colors are ok. From a friends pc every field with the word
email in had a different colour. When I change the spelling of "email" to
"emial" the colours displayed on his pc revert back to the colours I have
set. We are running identical versions of windows and msie. Except mine is
the Swedish version and he has the English version.

The offending field contains a text label and an input control. If either
the text label or the name of the input control contains the word "email"
the colors are morphed. The main problem with this was that the input field
was changed to yellow text on a yellow background.

Is this because I am supplying the colors by php code or is it a problem for
all forms? What I can not fathom is why he has different colors to the ones
I have designed and why this "feature" was not displayed on my pc. We both
use std settings in MSIE.

Why No Change In Fileatime?
When I write to a file, the fileatime does not update - how can I get the
mod date to update when writing to the file?

//increment counter value by 1
$counter=file($ctr);
$oldct=each($counter);
$newct=$oldct[value]+1;
//write new value to viscounter file
$fp=fopen($ctr, "w");
if (flock($fp, LOCK_EX))
{
fwrite($fp, $newct);
flock($fp, LOCK_UN);
}
//if cd not get lock, don't count this hit
fclose($fp);
echo "counter = ".$newct." visit at ".fileatime($ctr);
// fileatime($ctr) stays the same...


Copyright © 2005-08 www.BigResource.com, All rights reserved