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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Replacing $string Within An Array


I am reading in a text file, using : file("myfile.txt");

and in this file I have a form, but instead of having the HTML I have text field for a text box, and cbox for an option box with a yes or no. I am then replacing all instances of "text field" with <INPUT TYPE="text" NAME="txtbox[]">. I have this page submitting to a page that is supposed to take the values submitted from the last page and replace all instances of "text field", in the text file, with the values submitted right now I am using Code:




View Complete Forum Thread with Replies

Related Forum Messages:
Replacing A String In A Larger String
i want to remove an email from a list of emails stored in a text file. using
str_replace i can replace an email with nothing, but if the list is serated by commans, that would result in this:

email@...,,email@...,email@...

with no email between 2 commas. if i replace the email address with a comma on
the end with nothing, it wouldn't work for the last one. if i replace the email address with a comma at the beginning, it wouldn't work for the first one. how can i avoid this or work around it?

View Replies !
Replacing In String
Could anyone help me to write a function which would chanfe the string like
this:

"content [foto 1 l] content content content content[foto 3 f] etc [foto 21
r]"

into
"content <img src="img/1.jpg class="l"> content content content content<img
src="img/3.jpg class="f"> etc <img src="img/21.jpg class="r">"

View Replies !
Replacing Part Of A String
I am using the command ereg_replace() to replace " with ' . For fast web pages, I use Microsoft Frontpage and it has everything use ". I have to change them all to use ' .

The code is writen and it works, sort of. It has some text displayed at the end I don't want. Here is the my code:

View Replies !
Replacing A Portion Of A String
I am writing a guestbook program that allows the user to enter a link into their message, very similar to the vBulletin method above.

They click the button, and they get a prompt for a url, and an optional title.

If they enter a a URL, but no title, they string that is entered into the database is:

[H][A]http://www.website.com[/A][/H]

And if they enter both a URL and a title, the string looks like:

[H][A]http://www.website.com[/A][T]Title of Site[/T][/H]

The H tag signifies the beginning and end of the hyperlink string
The A tag signifies the beginning and end of the address
The T tag signifies the beginning and end of the title.

Now, when it pulls the data from the database, it performs the following actions:

View Replies !
Need Help Replacing Character In String
I have a string value ($test = "1,3,4,5,6,6,1,5"). As you can see, some numbers repeat, and some are not in order. What I want to do is remove just ONE of these numbers (so that if I remove a 6, my new result is $test = "1,3,4,6,1,5"). I know that I need to somehow traverse this data and tell PHP to remove (preferably) the first instance of the number I want to remove. This is the code I current have:

View Replies !
Replacing A Certain Number In A String
i have a string:

$string = "0|1|2|0|1|0|2|1|0"

and i want to replace any number in that string.so say i wanted to replace the third number that would be the number 2 in the string.Ok with me? now how can i do that? this is a string to show block modes on a site im doing. When i say modes i mean if its closed, minimised or just normal.

0 = normal
1 = minimised
2 = closed

this string is joined with another string that holds the block id's so they relate. but anyways could someone help me here? you can't use preg_replace() because your replacing a number in a certain postion not all of them!

View Replies !
Replacing A Unknown String In A Url
what i need to do is to get a string and replace it, but i don't know what the string is.
example: I have the url

<a href=http://www.blabla.com>this is a link</a>

I want to replace "this is a link" with nothing! remember that "this is a link" isn't always the same, so i can't say $blabla = str_replace("this is a link", "", $blabla);

View Replies !
Replacing Words In A String
If I have a textfile of words, each word on one line:

dog
cat
viagra

for instance, and I get them into an array, how then can I replace those
words in a string with something else:

"The quick dog took viagra and the lazy cat was unhappy."

I want it to say:

"The quick ### took ### and the lazy ### was unhappy."

I've been banging my head against this, with foreach (both forms) and
rtrim, and preg_replace, and str_replace, and I can't get it to replace.

I don't need to see code, just a general "algorithm" would be useful.

View Replies !
Replacing Characters In A String
I am writing a search engine with PHP which takes the search string and checks it inside a mySQL table using a LIKE statement with the variable enclosed in %s.

The engine is for an aviation site. So for example, I would like things like "F-16", "F.16", "F16", and "F 16" all to generate the same hits, say, by turning it into F%16.

I believe the correct PHP function is ereg_replace but I have no idea how to actually use it because I am unfamiliar with all the characters used in these types of functions (all the / } [ whatever).

View Replies !
Replacing Parts Of A String
I want to display only the last four digits from a credit card number. I can't figure out how to either split or explode the string containing the card number. i.e.

$str = ?'

How do I split or explode it to have access only to the last four digits?

View Replies !
Preg_replace Not Replacing At End Of String
I have the following code:

[code] ......

my string may be

"hello"

when I export the file - the tabbed spaces are replaced by squares.. the above example would come out as

[][][]hello[][][]

I cannot get the above code to remove the tabs from the end of the string - they are removed from the beginning, but not the end!

View Replies !
Replacing Certain Letters In A String?
I'm having some URL/SEO Issues. I have a video website, and for the sake of SEO, I put ?video=blah instead of ?videoid=##. Now, the spaces are replaced with %20. This is really bad when it comes to SEO. A user will probably not click something that has a bunch of %20s and such when they see it on an seo. Now, Is there a php way of replacing certain letters in a string?

I got: $foo="Coding Forums";
I want: $foo="Coding_Forums";

*Note, I don't make urls, they are automatically generated off of the mysql.

View Replies !
Replacing Multiple Characters In A String
I want to remove some characters from form input. Using this:

$comment = str_replace('example', 'Example', $comment);

works great, but how would I replace more than one charcter or string? Would it be done with an array? I knew how to with Perl, but I can't find the equivilent in PHP.

Also, for security purposes, would removing characters like ";<>&*~|#" from the form input be a good start in keeping my forms less open to sneaky coders? Maybe replacing those characters with the ISO character set numbers? This is for a guestbook-type page, so I feel that high security isn't that necessary for the file the input is being written to. I just don't want people to be able to screw around with other files via the form.

View Replies !
Replacing Two Strings Within A String And Copying What's Between Them
Yeah, kinda hard to sum up in a title. Basically, I'm trying to do something like BBCode, but I'm only making one tag--a link tag. For example, a user types [url]http://the.wesite.com/[/url], then the php code replaces [url] with <a href="http://the.website.com/"> and [/url] with </a>. Then the URL would appear again between the <a> tags. I've tried looking around, but I can't figure out which of the many string replacement functions I need to use.

View Replies !
Replacing Array With Mysql Result
I wanted to repalce the following line of code $data = array(40,21,17,14,23); with

for($i=0;$i<$numrows;$i++)
{
//print(mysql_result($result,$i,2));print("<br>");
array_push($data,mysql_result($result,$i,2));}

where mysql_result($result,$i,2) is the value and when i print it displays the values. But $data array is the Y axis value for drawing a chart. Here I wanted to replace the hard coded value with values from mysql but the second code does not function. Does anybody have idea how can I replace the $data array or what may be the problem with my coding The first one works but the second one does not work but in both cases it does not display any error.

View Replies !
How To Sort An Array Without Replacing The Indices?
How to sort an array without replacing the indices? I have an array indexed by a timestamp and wish to sort based on that in numeric ascending order.

View Replies !
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there.....

Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation...

Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:

View Replies !
Array String Into Associative Array
On one server I have a mysql query pulling data out of a database, and then printing the results. These results are then pulled from another server Code:

View Replies !
"Array To String Conversion" Error When Constructing A Multi-dimensional Array
I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);

It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

View Replies !
String From Array Value
The below variables are arrays, I want to create a string from the array values and I'm not sure how to bring them all together:

$wholeNum = $_POST['wholeNum'];
$fraction = $_POST['fraction'];
$measure = $_POST['meassure'];
$ingredient = $_POST['ingredient'];

example: $string = $wholeNum.' '.$fraction.' '.$measure.' '.$ingredient

View Replies !
String To Array
I've been really battling with this feature. I seem to have it right up until the part of rebuilding the array from the string. Herewith is my array2string code:

View Replies !
Add To String Array
Can anyone tell me how to add extra strings to an exsisting array

$data = array("AAA","BBB","CCC");
$data . "DDD";  // dosn't work.

View Replies !
Array To String
I have a array like so

// results from db
$v[0] = 'blue'
$v[1] = 'red'
$v[2] = 'green'
// the size of the array can change based on the number of the colors for each product
// I need to output it in a input text box like the following $value = 'blue,red,green'
// I figure some type of loop but I' don't know which one

View Replies !
Get Array From String
I would like to store data from a string in a database after some stripping. So for example:

<li><a href="xxx">yyy</a> - zzz
<li><a href="aaa">bbb</a> - ccc

In this example (which is one string) I would like to store the variable data in a MySQL table. In order to do that I need to first get the variable data from the string, which I can manage I think. But how do I get the data into the database? Do I need to insert the data into one or more arrays? And how can I then insert it into the table?

View Replies !
String From Array
I have an array

Array
(
[0] => SamplePictures/Blue hills.jpg
[1] => SamplePictures/Sunset.jpg
[2] => SamplePictures/Water lilies.jpg
[3] => SamplePictures/Winter.jpg
)

View Replies !
Array["string"] Or Array[string]
array[string] seems to work well the same way as array["string"] - i know array["string"] is the right way to do it but does it matter ? will it change in future versions of PHP ?

View Replies !
Unpack String Into Array?
I'm reading 512 bytes of data from a file. The C structure that wrote the data is of this form:

struct eu_data {
float time_data[124];
int count, bptr, fptr;
};

I'm trying to unpack it like this:

$datarecord = unpack("f124timedata/icount/ibptr/ifptr", $dataline);

How is "timedata" stored? How do I get at the individual numbers?

View Replies !
Retrieve URL Array From $string
Is there a way to retrieve an array of URL's from a text string? For example:

$string = 'This is a <a href="www.site.com">string</a> of text with 2 URL's, one of which is http://site2.com'

I want code that gives this array:

$url_array = array('www.site.com' , 'http://site2.com')

View Replies !
How To Add String Elements To The 1 Array
I have an array that contains numbers in string elements , i want to convert
this to integers, i have made a for loop that uses the number of elements in
the array and then adds 0, thereby converting it to an integer.
//$chars is the array of strings

for ($i=0; $i<$numpoints; $i++) {
$array = array($chars[$i] + 0);
}

I dont know though how to add all these elements to the 1 array, it
replaces each element in the array with the new item,

View Replies !
How To Unpack A Very Big String In An Array
I need to unpack one string with more then 2000 chars in several pieces!! In perl i make this:

$FORMAT = "A4 A4 A3 A7";
$string = "nameemailteladdress...";
@unpacked = unpack($FORMAT, $string);
result:
$unpacked[0] = "name";
$unpacked[1] = "email";
$unpacked[2] = "tel";
$unpacked[3] = "address";

But in PHP 4.02, How I do this I already try:
$array = unpack("A4/A4/A4/A4"); and examples of www.php.net but nothing!!

View Replies !
String List To Array
I'm trying to convert a slash-delimited string to an array, but I'm
wary of null elements that I want to eliminate. I'm frustrated with
explode(), array_unique(), and array_pop(), and I'm wondering if
there's a better way. I'm only interested in unique array elements.

Here's what I've got

$a = "10/20/30"
should become an array where
$b[0] = 10, $b[1] = 20, and $b[2] = 30.

Now here's the fun part. Often my arrays will have
$a = "10//"
I'd like that to become $b[0] = 10 and that's all.

So I tried applying array_unique() to explode("/", $a)
but you have to be careful about how many elements
are returned. Then I tried to use array_pop() to drop
the last element if it's empty, but array_pop returns
a scalar string when there's only one element left.
So when you use $b = array_pop($q), sometimes
there is no $b[0].

View Replies !
Is $Settings['string'] An Example Of An Array?
I'm still pretty new to PHP and I have a question. I know that
variables are preceeded by a "$" (dollar sign). Typically, a variable has
one value, unless it is an array. Then it is essentially a pointer to
numerous values sequential in memory. The code I'm looking at now is using
the same variable name, but assigning a different "index" to it, if you
will.

For example, I see the following:

$settings['use_default_images']
$settings['doctype']
$settings['theme_url']

And many more.

What is this feature called in PHP? I looked at the reference on php.net
and it isn't anywhere to be found under arrays.

View Replies !
Creating A String From An Array
I want to concatenate a number of db entries into a single string (forming a summery) I’ve come up with something that illustrates the principle, I can  see that I need some sort of loop that reads each array element into the string, and then exits the loop - however my lack of experience has now got the better of me. Code:

View Replies !
Check Array For A String
I am trying to set up a blacklist for a service I'm making. My current objective is to call up a .txt file which contains one domain name per line. I then take the user's input from a HTTP post and check to see if it contains the domain name. Here is my current non working script:

//take user's input (example: http://www.somesite.com/files/photo.jpg)
$filename = $HTTP_POST_VARS['filename'];

//load blacklist in case of abuse
$blacklist= file('blacklist.txt');

//check submitted image against blacklisted domains
foreach($blacklist as $site){

if (strstr($filename,$site) !== FALSE) {
echo "<div><h3>This site is blacklisted</h3></div>";
exit();}}

This doesn't seem to work at all. I think it has something to do with the variable types, but I am too unfamiliar with this for Google to be a viable solution.

View Replies !
Turning A String Into An Array
Is there any way to turn a string into an array (well obviously there is a way to do it, i just cant figure out how)

i was thinking there must be a class in PHP what allows you to do that, either in a loop, or something built in. i.e.

class_name("4", $mystring);

View Replies !
Convert From Array To String
i am having a small problem with my code i want to convert from array to String. i tried using the (string) casting but it doesnot work?

View Replies !
Make A String Into An Array
I know there's a simple function to do this just can't remember it. Say I have a string with spaces in it like this: jpg jpeg gif png. How do I break this into an array or manipulate each piece separately basically (I need to check each file type with a string of file types).

View Replies !
Array Exists In A String
How am I able to use an associative array key to search for a string and echo the value?
PHP Code:

<?php
$haystack = "My name is Allen";

//works with this style array
$names = array("Mike", "Joe", "Bob", "allen");
echo arrayinstr($haystack, $names);//echo's allen

//How do I get associative style arrays to echo the sex (male) instead of "allen"? (male,female,alien)
$names["Bob"] = male;
$names["Sally"] = female;
$names["Charlie"] = male;
$names["Allen"] = male;
$names["Android"] = alien;

View Replies !
Find A String In Array
i have this array:

$str = array("apple is red", "banana is yellow", "pineaple is tropical fruit", "coconut is also tropical fruit", "grape is violet");

i want to find string "coconut" inside $str and put the whole string "coconut is also tropical fruit" into variable $coconut. Code:

View Replies !
Occurances Of A String Within An Array
I have an array:

$myarray = "A1&1&^B1&1&^C1&1&^D1&1&^B1&1&^"

You can see that this is an array within an array, The first set of information is separated by the ampersand while the array itself is separated by a karat.

Doing a explode of ^ I would get:

$myarray[0] = A1&1
$myarray[1] = B1&1

Doing an explode of & I would go
...

View Replies !
File_get_contents Array/string
PHP Code:

$content = File_get_contents( "http://www.counter-strike.net/" );

This works, PHP Code:

$matches[0] = $url;
$newcontent = File_get_contents( $matches[0] );

But this doesn't :/ I've got the syntax wrong, does it need quotes or something?

View Replies !
Random String From Array
If i wanted to pull a random string from an array, lets say for like a quote of the day

$quotes = array('quote1','quote2','quote3','quote4');

$todays_quote = ?

What function could i use to provide the variable $todays_quote with a quote from our list?

View Replies !
Array $row Values To $string
is there a function to convert all values of array $row into seperate variables:

$row = mysql_fetch_array($result);

// i dont want to have to do this anymore :-)

$name = $row['name'];
$address1 = $row['address1'];
$address2 = $row['address2'];

View Replies !
Split String Into Array
Split a string at "-", "_", ":" and " " (space) and place the result in an array?
Example: "hello there:whats-up_dude"

>>

$array[0] = "hello";
$array[0] = "there";
$array[0] = "whats";
$array[0] = "up";
$array[0] = "dude";

My script got way too long.

View Replies !
Convert String To Array
With a string like this:

$Data = "45,'Dog',33.2,'Cat','Bird'";

I need this result:

$Arr = array ($Data);

$Arr[0] = 45
$Arr[1]=Dog
$Arr[2]=33.2
$Arr[3]=Cat
$Arr[4]=Bird

View Replies !
String Offset As An Array
PHP Code:

<?php
// Declare variables //
$debug = false;
$url = "http://www.mto.gov.on.ca/english/traveller/conditions/rdclosure.htm";
//$url = "./roadclosed1/rdclosure.htm";
$email_recip = "REMOVED";
#$email_recip = "REMOVED";
#$email_subject = MOVED TO LINE 47
$email_from = "WxServer Roads";
$email_from_addr = "REMOVED";
$message_header = "
====START====
.......

View Replies !
Array To String Conversion
Notice: Array to string conversion in c:inetpubwwwrootidximportprojectfileimport.php on line 6

<?php
//Load file into variable for tab sorting.
$listingres = file('Listings-Residential.txt');

//Use explode function to put tabbed array into the variable $string
$lines = explode(" ", $listingres);

print_r($lines); //Print out readable data about string

?>

View Replies !
How Can I Include An Array Value In A String? (Was: This Is Stupid!)
echo "authenticateduser = $_SESSION['authenticatedUser'] <p>usertype = $_SESSION['userType']";

generates an error...why?? I can normally include HTML + PHP in an echo string!

View Replies !
Save String Chars In An Array
Can anyone please suggest a piece of code that goes through a string and then saves the character information in one array as in the example below?

$string = "Thiiss is my String";

char[0] contains "T";
char[1] contains "h";
char[2] contains "i";
char[3] contains "i";
char[4] contains "s";
char[5] contains "s";
char[6] contains " ";
char[7] contains "i"
and so on...

What I need is to know the location of each letter in the string.

View Replies !
Make Associative Array Out Of String
I have a string that look something like this:

$string = "weight, kg|1200|width, mm|220|prize|20000";

and I would like it to an associative array and print keys and value:

weight, kg: 1200
width, mm: 220
prize: 20000

(The string above is fetched from a database)

Anyone have any bright ideas how to do it?

View Replies !
Sort Array By String Length
I've been muddling through functions to make a small search engine. I'm at the point where I have each word and its position in an array, the word position being the key and the word as the value.

Each word gets hashed to an integer value, and it's useful for me to have the values in the array ordered by their string length (in ascending order) to do this.

After a gander through the array functions in the PHP manual the closest match I see to this is uasort(array,function cmp_function)

Would this be the right function to use? And if it is, any idea what the function would look like to get them in ascending order of length...

View Replies !
Removing Element From Array Using String
I am trying the following based on an example from php.net

<?php

$array_of_items = array ('A','B','C','D');
array_splice($array_of_items, 'B', 1);

foreach ($array_of_items as $array_of_items2)
{
Print $array_of_items2;}?>

I expect the result to be ACD, I am getting BCD, Not sure why.

View Replies !

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