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 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 Complete Forum Thread with Replies

Related Forum Messages:
Replacing Strings
I'm setting php to get the contents of a flat file (Not the same from the previous post) and inside of it are names of people in my database. What I want to do is replace these peoples names with their unique member ID. Problem is there are 3500 of these people in the database and their names are repeated several times each througout the text file. (Though only about 1200 of them are in the file they are repeated numerous times.

View Replies !
Replacing Strings With Dynamic Content.
I am writing a template function, and want to replace a string such as <*price*> With the value that price is a MySQL database. For example, I have a page that is
page.php?cid=3 Code:


View Replies !
Replacing Strings On External Links
I've been trying to figure out a way to make this work with Wordpress all day and I cant figure it out for anything.

Basically what I'm trying to do is  replace < a href="#"  with < a rel="nofollow" href="#"

but only for external links... anyone know how I could get this to work? I'm not skilled enough to create the script from scratch and I'm having trouble finding any answers

What i'm trying to do: Code:

View Replies !
Copying Variable Part Of A String
I have strings like these:

$line = "Item <name> xxx stock, costs yyy and will sell for amount zzz";

Problem is <name> can consist of 1..n words. Most items are single words,
but some are up to 8 in my example, and there are is no set maximum (well,
max is 80 chars I believe, have to look in the stock db, not too relevant I
think)
I found this out the hard way. I thought I was clever (never do that again)
by doing this:
$words = explode (" ", $line);
$itemname = $words [1];

This only works for single-word names.

Now I want to create or use an existing function that simply copies
everything between Item and the first numerical substr.
The function then should look like:

$itemname = GetSubStr ("Item" , <numerical> , $line);
<numerical> should be a template of some sort I think.

View Replies !
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 $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 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 !
How To Find Several Strings Within A String
I'm trying to find several keyowrds out of string of text which are the list of keywords for a text file. The keyword list is in a field called keywords in a mysql database.
So if the user types in "foo bar foobar" to be looked up and the field contians "Bar foobar foo oyster moregarbage stuff" it will be able to bring up that record.

View Replies !
Split String In Smaller Strings
I have a string consisting of say 1000 characters. Want I want to do is to split the string at the first space after the first 80 characters, enter a <br> tag and after the <br> tag carry on with the rest of the string.

Then it needs to repeat this with the remaining string and split it again at the first string after 80 characters till it reach the end of the string. I got it in a way to split it after 80 characters and enter a <br> tag, but it's not working properly and I don't have any idea how to repeat it. PHP Code:

View Replies !
Split The String Into Two Separate Strings
I have this variable:

$str = "4xAura Extraction";

I need it to split the string into two separate strings containing this:

$split[0]: 4
$split[1]: Aura Extraction

I can't use explode(), because that will split it up again if there are x's other than the one that comes after the number. What would be the best way to get this done. I'm asking because I'm not real good at string manipulation when it comes to mutilating them.

View Replies !
Adding Strings To A Query String?
I want to use my string $stringvar to show text in this sql query. ATM its sticking "$player, $score" into a field, I want it to instead print it out into the sql statement.

This is my code:
$stringvar="$player, $score";
$sql=mysql_query("INSERT INTO $game_db VALUES ('$new_matchid', '$opponent', '$map', $stringvar, '$result')");

This is what I want the sql query thing to look like:
$sql=mysql_query("INSERT INTO $game_db VALUES ('$new_matchid', '$opponent', '$map', $player, $score, '$result')");

View Replies !
Set An Array = To A Comma Delimited String Of Strings
is there anyway I can set an array = to a comma delimited string of strings and then loop through each of those manipulating the string. help me with the basic code for setting up the array and looping through it.

View Replies !
How To Search Strings Escaped By Mysql Real Escape String()?
I am currently developing an article script and there are Titles and Contents. To prevent sql injection, people say we must use mysql_real_escape_string().

So let's say if there is a Title that says "My Friend's best friend", if I look into the MySQL table record, the text will be saved as "My Friend's best friend", where the apostrophe is escaped. Code:

View Replies !
Why Is Preg_match_all Slower On A Large String Than In A Loop Of Smaller Strings With The Same Overall Length?
While using the following loop to extract images from the google search
engine I discovered that preg_match_all works much faster parsing small
strings in a loop than extracting all of the urls at once from a much
larger string.

This surprised me because I expected the preg_match_all to perform the
task much faster. Why is this, and is there an easier way to resolve
this matter?

for ($i = 0; $i < $m; $i++, $start+=20){
$saURL = "http://images.google.com/images?q=" . $searchString .
"&start=" . $start;
preg_match_all("/:(wwwS+?.(jpg|png|bmp|gif))/i", file_get_contents(
$saURL ), $matches);
$image = array_merge($image, $matches[1]);
}

View Replies !
Need Function: Split String By List Of Strings And Return Delimiters And Extra Text
I am looking for a function that takes in a string and splits it using a
list of other strings (delimiters) and can return the delimiters as well
as the extra parts of the string. I was trying the split with a regex
built up of the delimiters separated by "|", but it doesn't return the
delimiters which I need. Code:

View Replies !
GD Text Proc Via OK For Local Strings, But NOT For SESSION-passed Strings. Why?
i've php-5.1.2 built from src on OSX 10.4.6.

GD-2.0.33 + libpng-1.2.10 are built/installed/enabled.

GD is working fine ... locally.

in a given php file, this returns an image as expected: Code:

View Replies !
Splitting Strings - Break Strings Apart By Character
I am trying to make post code search and need to be able to break strings apart by character. I can do it by spaces and things using the explode() function, but I want to be able to get the first letter of the string only, the first and second only, first second and third etc.

View Replies !
Copying Into New DB
I just got a enw script and its way cooler than the one i made. (more features). I want to transfer files between db. I need to do this via php because it needs some tweeking.

How do I transfer between databases?

I was thinking of getting a while fetch array going and then insert each one into new row, but its still in same selected db...

View Replies !
Copying Files
The situation is I have a template.php file, and I wan't my script to copy this file and give the new copy a new name.

This is the code so far, but it doesn't copy...

$temp = "template.php";
$file = $linktextdata . ".php";

if (!copy($temp, $file)) {
echo "copy of $temp failed";
}

I test echoed the variables, and they look ok.

View Replies !
Image Copying
I have this form tag to send an image to my message board: <input type=file name=picture> and the enctype="multipart/form-data" in in the form tag. I them use $picure_name to do two things.

First, I alter the message the include the img tag using str_replace. That part works fine. I then try to copy the message to the images directory:exec("cp $picture /full/path/to/mbimages/$picture_name");

The image never gets there. I don't get any error messages, but the image never shows up in that directory.

View Replies !
Copying A Directory
I think i can use copy() to do this, but i just dk how :S.  i can only get it to copy files.

I need a script that can copy a folder, and all the files in that folder, and "paste" it in a new directory. 

View Replies !
Copying Folder
I want a script that when you run it It copies a folder and all of its contents.
Every time you run the script it would copy www.mysite.com/folder/ once

www.mysite.com/folder/ www.mysite.com/folder1/ www.mysite.com/folder2/

View Replies !
Copying From MS Word
Everything works ok until they try and copy text from MS Word. When they do this, apostrophes change to a capital A with a accent above it. It looks ok in the text box but the wrong character gets put in the database.

Then when you go back in and edit the page, the A character is there and can be replaced.
If they replace the faulty character then it all works fine but it's just a pain for the end user.

View Replies !
How To Add Copying Progress Bar In PHP?
How to add copying progress bar in PHP? like attached image file.

View Replies !
Copying Problem
I am trying to upload a file from a form and keep getting the following error

failed to open stream: Permission denied

The file is trying to upload an image to a folder that is at a higher level.
E.g. The page is in folder url/cumbria, and is trying to copy the file to url/uplimg

The page calls a function from a seperate function list: Code:

View Replies !
Copying Records
Right now for my php web app with pgsql, I have a section where the user has a list of software and an input box next to each title where you input how many copies are going to be used.

The whole form mainly deals with 2 tables:

softroom[rid, sid, added, total]
software[id, title, version, site, ltype, lnum, platform]

So the user picks a room which has an id, and then inputs amount for titles, example

room 250
flash 20
ms word 20
ms excel 20

and then it inputs in the db

softroom[ 4, 1, 20060101, 20]
softroom[ 4, 2, 20060101, 20]
softroom[ 4, 3, 20060101, 20]
softroom[ 4, 4, 20060101, 20]

now the problem is that each form, I usually enter liek 50 titles, and it takes time, and the thing is that the next room i have to input software stuff has the same software but different amounts for example for room 350:

room 350
flash 30
ms word 30
ms excel 30

and then it inputs in the db

softroom[ 5, 1, 20060101, 30]
softroom[ 5, 2, 20060101, 30]
softroom[ 5, 3, 20060101, 30]
softroom[ 5, 4, 20060101, 30]

Is there a quick way of copying records in a db but just change the amount and room id or something?

View Replies !
Copying With Quotes
I have a data entry form that stores data into a mysql database. The problem I have is if someone enters a quote (' or ") into the field, it breaks my code.

mysql_query("insert into tasks(item,priority,status,accountable,review,notes,creator) values('$item', '$priority', '$status1', '$accountable', '$review','$notes','$user')");

How are you supposed to deal with quotes? Is there a best practice method?

View Replies !
Resampling And Copying
if a user uplaods an overly large image, once it has reached its final resting place i want to resize it and then delete the old, large file. My code so far is this:

<?php
$filename = "test1.JPG";
$percent=.25;
//first resample it
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

//now copy it

if(!copy($image_p,"resampled_".$image_p)) {
echo "Failed to copy file.";
} else {
unlink($filename);
}

?>

however i get a warning:

Warning: copy(Resource id #3): failed to open stream: No such file or directory in c:program fileseasyphp1-8www esample.php on line 23

why is this doing this? Also i have no idea what Resource id #3 means, where could I find out?

View Replies !
Copying Remote Files
How do i copy a picture or another file from a remote webpage, and put it into my webpage dir?

View Replies !
Copying From One Mysql Database To Another
Is it possible to open a connection to two separate mysql databases in order to copy the data from one table in the first database into a table in the second database? I'm assuming the answer is yes, but I'm confused as to the proper php syntax.

View Replies !
Files And Folder Copying
I am trying to write a function to copy an existing folder and folder
structure but am already stuck.

What I want to do is the following:

Copy a default folder (default_folder) and all sub folders within it (down
to a possible 4 levels)
eg default folder
->subfolder1
->subfolder2
->sub subfolder1
->sub sub folder 2

I have a form where the user can enter the name of the new folder and an
option to confirm if they want to copy the files also located within the
default folder.
If the checkbox is not checked then copy just the folder structure only

Can this be acheived in one function or will it be based on 2 where a set of
empty folders are created and where the folders and files are copied over

View Replies !
Copying Entire Directories
I need to copy all of the files from one directory to another. This has to happen on the fly. The files that are being copied are actually templates for another site that will be created. I have seen the example on php.net under the fopen section but it doesnt work.

View Replies !
Copying Rows To Another Table
After I select a row whose ID is 10 or some other number, I need to
copy the entire row into another table.

Is there a way to copy rows between tables using PHP? Could someone
please point me to an example..

View Replies !
Copying Files From One Server To Another
I am trying to set up a link excahnge program using php and I need to know how to copy a file from one server to another. See when people change the banner they have displayed they can enter the location of their banner, such as http://them.com/banner.gif and then i need to copy it over to my server and into there dir, such as www.me.com/them/banner.gif. Does anyone know how i can do this. I have tried many things but nothing has workd so far.

View Replies !
Copying Old Folders To A New Location
I'm trying to write a page that would make a copy of a set of folders to a new location for an intranet. There is lots in the page for debugging that would vanish once I get it to work. The problem I'm getting is I cannot get XCOPY to work. Other dos commands work fine. Code:

View Replies !
Copying A File From On Server
Let's say I have a file on my server at location:

/public_html/Global/oilers.php

...and i want to copy this file and save it to another directory (using ftp commands):

/public_html/hockey/Oilers/oilers.php

How would I go about....   I gigured out how to login using ftp commands and explored the ftp command available.. (eg.put, get etc..) but I'm not sure which command to use..  can someone point me in the right direction?

View Replies !
Copying Files Using A Loop
I have a spreadsheed with names and image urls that I have converted to a tab delimited text file. Column one has the product  name and column two has a url to an image on another site.

I am trying to loop through the file and copy the image onto my computer, but it is giving me this error: "Warning: copy(http://ec1.images-amazon.com/images/I/41Oj92a63gL._AA280_.jpg ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:Program Filesxampphtdocscopy.php on line 16" Code:

View Replies !
CopyDir (Copying One Directory To Another)
I was wondering if it was posible for someone to point me in the right direction.

What i need to do it copy the contence of an entire directory to another designated destination, is this possible and if so could someone point me somewhere i where i can figure it out.

View Replies !
MySql Copying A Whole Row Into The Same Table
is there a quick and easy way to copy a whole row in a table and copy it the same table? obviously i want the ID to change to the next auto_increment value.


View Replies !
Putting My Old Site In To A New One Without Copying Old
can i convert my old site in to my new one dynamically. is this possible. i heard someone talk about it but am not sure how to do it.

View Replies !
Copying Entire Folders
I am trying to copy a folder (which has subfolders and those subfolders possibly have folders) to a destination. I tried using PHP's 'copy' function, but it didn't work. I know I have my $src and $dst variables pointing to the exact places I need, but it just isn't working. I am not getting any errors, it just doesn't do the copy. Is the PHP copy function only for files or can it work for folders as well?

I heard about the XCopy command also. Can you anyone give an example of using that?

View Replies !

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