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.





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

Related Forum Messages:
How I Can Find Longest Common Prefix Of Strings
I'm interested in such algorithm that solves problem of finding longest
common prefix of two or more strings.

I haven't found such function in PHP, or I pass it?

View Replies !
Reg Ex Expression - Find Any Block Of Strings 40 Or More Characters In Length
This reg ex will find me any block of strings 40 or more characters in
length without a white space, yes?

[^ ]{40}


To get it to include tabs and newlines, do I to this?

[^
]{40}

View Replies !
Grep Command To Find Strings Across Multiple Lines
I'm trying to find queries with multiple lines:

$query = "insert into
{$db_name}.tbl_memo values
('xxx', xxx, ....)

Anyone help me with "grep" command to find these strings cross multiple lines?

View Replies !
Find String In String In File With Repeating Data
I have files with the following data:

*******************
SEQ: [+1]
DTM: [203:20050914:102]
FII: [OR+05407059214]

SEQ: [+2]
DTM: [203:20050915:102]
FII: [OR+05407059999]

SEQ: [+3]
DTM: [203:20050813:102]
FII: [OR+05407099999]

and so on....
*******************

The file could have 1 or 100 sections and I recieve them every day. Code:

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 !
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 !
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 !
Find And Cut String
I'm new to PHP, so please bear with me! =)

Is there a nice little function to find a string between to html-tags?
I.e. let's say I have a string with the following text:
"Hello world, <b>this is a test</b>"
I would like to cut out the text between the <b> and </b> ("this is a test").

View Replies !
Find String
Surely there's a function for this. But I can't find it. I need to search for a string. plenty of those of all flavors,and when I find it I need to capture the following x characters.

Examples:

search the string for 'user=' I don't know who the user will be but it's a 8 digit name/number that follows. I need to capture the info that follows.

other examples..
module=
name ( )

View Replies !
Find A String
I'm setting up a database search and want to be able to find strings that are part of an array value. For example, if my database has "cats, dogs, goats" and someone uses "cat" as the search query, I want "cats" to be found in the array. I know you can use in_array for EXACT matches but is there a way to find LIKE-type matches in values in an array?

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 !
Find Last Occurrence Of A String In Php 4
Can any body tell how i can trap last occurance of a string in a string. I use strripos()function to do this. But it is available in php 5 ont in 4. And there is php4 installed on my web server. So my scriptting is not running properly. Can any body tell substitute of this function in php4.

View Replies !
Find One String Inside Another
How can I find one string inside another. i'm looking to do something like:

if str("my sentence here", "sent") {
do something }

View Replies !
String Find And Replace?
What would be the easiest way to check if a string has a certain text in it. If it does not, add it, but if it does, do nothing. I don't want it to be case sensitive either. Code:

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 !
In A String Find Out If It Contains A Mailadress
For a given string, I need to find out if it contains a mailadress, and if it does I need to replace it with soemthing else. I tryed using preg_match and preg_replace but can't get it to work. Does anyone have a clue?

View Replies !
Find The Length Of The String
I want to find the length of the string.That i did by using strlen().now i want to put it in an array .

View Replies !
Find A Html Tag In String
$string=' this is image 1 <img src="www.abc.com/abc.gif"'> and second is <img src="www.df.com/edfg.jpg">;
function getAttribs($t, $a, $s) {
preg_match_all("/(<".$t." .*?".$a.".*?=.*?")(.*?)(".*?>)/", $s, $m);
return $m[2];
}
$arr=getAttribs('img', 'src', $string);

Here i get all the src of <img> tag.

View Replies !
Find Part Of A String
I am an ASP guy who has been converting to PHP. Anyway, I'm having a problem figuring out how to find part of a string.

What I am trying to do is to list any file that starts with "info". So I've got a while loop that will show all the files, but now I'm trying to figure out how to display only the files that start with "info". In ASP it would be like this:

If Left(strFileName, 4) = "info" Then
Response.Write(strFileName & "<br>")
End If

Does PHP have a function like this? In the example above it reads the first "4" characters in the string strFileName and compairs it to "info".

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 !
Use Ereg To Find Two Different Words In A String?
Can you use ereg to find two different words in a string (I'm trying to look for AND and OR) and then do two more ereg's to look for those same words but seperately.

View Replies !
Find Out If A String Contains Only Letters And Numbers
i'm pretty new to the preg_match() function and what im simply trying to do it find out if a string contains only letters and numbers, nothing else!  Here is what i have so far, tough it does not work:

if (preg_match('/^[a-zA-Z0-9]+$/', $catagory))
{
  //OK
}
else
{
  // NOT OK
}

View Replies !
Preg_match Find All Instances In A String
Im having trouble with preg_match_all. Im trying to make preg find all instances of test in a string, and then print out how many it found with a for loop. The problem is that only three test's are printet out. There are six in total. Below is the script :

<?

$text1 = "Test 1, test 2, test 3, test 4, test 5, test 6";
for ($t=0; $t<count($text1); $t++) {
  preg_match_all("/test/i", $text1, $match1);
  print "<br>".$match1[0][$t];
}
echo "<hr>";

?>

What am I doing wrong ?

View Replies !
Find Data Between 2 Characters In A String?
I want to find and display data found between two characters in a string.

Example>

Form sends the following to the .php page....

$data1 = "The Domain Name [somedomain.com] has been renewed";

I want to be able to pull out and display only "somedomain.com".

Example, I want a variable called $domain to only hold the domain name itself, without the brackets or the text.

somedomain.com

I have investigated function strstr().

$data1 = "The Domain [somedomain.com] has been renewed";
$domain = strstr($data1, '[');

OUTPUTS:
[somedomain.com] has been renewed

I can then use substr() to remove the first "[".

$domain = substr("$domain", 1);

OUTPUTS
somedomain.com] has been renewed

But, I am stuck, conceptually, with what to do to trim the end after .com . Note, somedomain.com will change. One run, it could be somedomain.com and the next, it could be "somethingelseentirely.com". Thus, the character length of that part of the string will change each time.

View Replies !
Preg_match() Help How To Find Two Words In A String
I am just now diving into learning use regular expression and my head is spinning with all the articles I have been reading. I think what is must confusing is all the symbols that are used when creating a regular expression.

I have a database that has a field I entered some keywords. Now Im querying the database to search the keywords for words I passed through a link. Code:

View Replies !
Find And Replace Query Variable In URI String
I am trying to find and replace the query variable relating to the session id "sid=". This is the portion of the script that has to find out where the sid= is in the string and replace it with an updated version that contains the session id. It is not finding "?s=" nor "&s=" when I run it any of the following urls.

http://www.mysite.com/?func=home&sid=
http://www.mysite.com/index.php?func=home&sid=
http://www.mysite.com/?sid=&func=home
http://www.mysite.com/index.php?sid=&func=home

I commented out the parts which do not have a bearing on the basic string search function.
PHP Code:

View Replies !
Function To Find 6 Digit Numeric String
I need to parse a string and attempt to find a substring in the string that contains 6 numeric digits. the first and last digit may or may not be preceded by a space.

I need to find the starting the ending positions of the 6 numeric digits to that I can extract the string and build an href containing the string and replace those 6 digits with a hyperlink.

View Replies !
Ereg And Preg Versions To Find If Any String Is Enclosed In Quotes
How do I write the ereg and preg versions to find if any string is enclosed in quotes??

"real estate" -> match
real estate -> no match

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 !
Use Preg_match To Find Out If A String Begins With Either "http"
I try to use preg_match to find out if a string begins with either "http",
"/somethime" or "../something". In my php script I have the following line:

if (0 == preg_match("/^(http.+)|(/[a-z].+/)|(..[a-z]+)/i",$string)

But I get a:

Warning: Unknown modifier ')' in myscript.php at line nn

What's wrong with the pattern?

View Replies !
Preg_replace With "[g]" As The String To Find
I'm having rpobs with this because my string pattern to find is "[g]" and when i use the following code :

$str = "this is the text to make [g]bold[/g]";
$str = preg_replace('[g]', '<span class="bold">', $str);
echo '<br>'.$str;

it just outputs this :

this is the text to make []bold[/]

so the problem is obviously the square brackets which seem to have some specific meaning in the regular expression. So i tried escaping the brackets with backslashes but that doesn't work - it just outputs this error:

Warning: Delimiter must not be alphanumeric or backslash in

could someone tell me what i need to do to be able to search for "[g]" and "[/g]" ?

View Replies !
Strings And {...}
Is there something build into php where {0} or {1} means something?

For example,

SELECT * FROM table1 WHERE col1 = {0} AND col2 = {1};

View Replies !
Strings
in my db i have dates stored like dd/mm/yyyy. how can i split the string up to get date = dd month = mm and year = yy. This is so i can then get an array on the month so it can show dd [month name] yyyy

View Replies !
Strings Cut Off
I am using PHP and MySQL to store information on customers. When a user enters their address (e.g. 75 Main Street) it goes into the database as submitted.

I have another form that allows the user to update their information. When I insert their data into this form, only the first word ( 75 ) is displayed. How do i go about getting the entire string?

View Replies !
With Strings
How would I make a page that excutes the strings and changes an include file when someone clicks a link that is linked to 'index.php?pageid=1'?

View Replies !
Joining Two Strings Into ONE?
I have no idea on how to joining two strings into ONE.
eg.
$str1 = "Hello ";
$str2 = "World.";

I want to make a string
$str3 = "Hello World.";

View Replies !
Preg_replace With Strings
I have the following text:

------------
<A HREF="http://www.webwater.de/single.php4?top=unscribe&sub=123-@f.gruber&langr=de">hier</A>
------------
now i want to replace this with:
------------
hier
------------
but "123-@f.gruber" is variable.
I tried this one, but is dosn't work:

$repf = "<A HREF="http://www.webwater.de/single.php4?top=unscribe&sub=";
$repl = "&langr=de">hier</A>";
$bodyde = preg_replace ("/$repf.*/$repl", "hier", $bodyde);

View Replies !
Sorting Strings!
Hi

I need to read a .txt file and sort the value, highest firs, lowest last.

The .txt file contains the following info on a different row:
altavista:joe:5
yahoo:eric:2
disney:dis:4

the firs thing i did was reading the first line and split the code by ":" so that
echo $referrer[0] //would give altavista
echo $referrer[1] //would give joe
echo $referrer[2] //would give 5

I want to sort these lines on the numbers(highest first, lowest last) and print this in a table. How can i do this?
so what i would like in a table is this

<table>
<tr><td>
altavista</td><td>5</td></tr>
<tr><td>
disney</td><td>4</td></tr>
<tr><td>
yahoo</td><td>3</td></tr>
</table>


Is this possible anyway?

View Replies !
Can Php Concat Strings?
Can php concat strings, it's not a fuction listed on the php site? what would the format be like, $output concat($str1, $srt2).

View Replies !
Breaking Strings?
I have a string (actually 100's of these, but lets take one):

$string ="TI: Some journal title AU: SomeAuthor,-S; Smith,-A; Jones,-B SO: SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90 JN: Some Journal Title";

This needs to be turned into an array:

$entry = array(
'Some Item Title',
'SomeAuthor,-S; Smith,-A; Jones,-B',
'SomeSource. 2002 Jan 9; 287(2): 188; discussion 189-90',
'Some Journal Title');

As you can see, each array item should be defined by what comes after either/all of the following: 'TI:' 'AU:' 'SO:' 'JN:'

So, I need to be able to create a pattern that can look through the string and return everything in between TI: and AU:, then AU: and SO, etc.

for example:

eregi(???, $string, $entry);

I'm fairly new to this and can't seem to figure out the regex I need for the pattern. Is this even the way to go about it?

View Replies !
Prepare Strings For XML
I was just wondering if anyone was aware of any prebuilt functions that would prepare strings for 'well-formed' XML. I.E. There is obviously a lot of various characters that do not work with 'well-formed' XML (&,$, etc.). I am looking for a pair of functions like stripslashes|addslashes; urlencode|urldecode.

View Replies !
Two Equal Strings?
I was just checking php.net but couldn't find a function that will compare to strings.

Did I just overlook it? or do I have to write a function to compare the two stirngs in php?

If there is a function, which one is it?
If there isn't a function, could you give me an idea of the coding that would compare two strings?


View Replies !
Query Strings
I have got query stings up and working on my site. But there are some problems. How do I make the title of the page change with the diff. index.php?page=

Also, I wanted the query strings to act like a frame, so when clicked it only changes the content, not the whole page.

I am using this code:
[PHP
<?php

if ($page=="whatever") {
include ("whereat");
}

elseif ($page=="whatever") {
include ("whereat");
}

elseif ($page=="whatever") {
include ("whereat");
}

else {
include ("whereat");
}

?>
[/PHP]

View Replies !
Appending Strings
How would I build up a string so that i get

$variable1 dynamically which should be used in a sql query like:

$sql = mysql_query("INSERT INTO **** (var) VALUES('$variable1');

the problem is that i need to run this 30 times and therefore need to create the $variable1, $variable2 etc on the fly - my problem is I cant get it working with my strings. Im using $i as integer in a loop. Tried things like
'$variable.$i' this wont work since i get the value .1 inserted.

View Replies !
How To Get Strings With Spaces?
I have a Select pop-up with list of country names with a variable $Country. I pass this variable using the URL to the next page and it displays fine. When I have a link from page two to page three, the Variable is cut after a space.
(e.g) Page one I select "United States of America". Page 2 shows it ok. But, on page 3 this variable is only "United" the rest is gone. here is the link i use:

<a href="Response5.phtml?Country=$Country&day=$day&month=$month&year=$year">$day</a>

View Replies !
Joining Strings
I must be doing something wrong, but I can't see it. I an trying to build a long string that is to be a mail message, but I keep getting an error. PHP Code:

View Replies !
Switching Strings?
I want to be able to switch a certain word in a string with one that is in an associated array( is that right?). Here is an example: PHP Code:

View Replies !
Strings To Lowercase
I want to convert a URL typed in /ANyCAsE/ to /lowercase/ - the following does work if the URL is lowercase already but not if mixed or upper case. What is incorrect?

<?php
$url_array=explode("/",$REQUEST_URI);
$url_category_type=$url_array[1];
$str = strtolower($url_category_type);
print $str;?>

View Replies !

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