Problems with php links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yjanni
Forum Newbie
Posts: 8
Joined: Wed May 22, 2002 3:17 pm

Problems with php links

Post by yjanni »

I have an html file that contains html (<a href...) links like
'domain.net/script.php?variab=value'

These are inside custom tags (<my_title>, <new_edit>).

I also have an script thats supposed to add some new entries into that
abovementioned html file AND also remove some of the older parts.

I've split the functionality into two parts.

Script A loads the html, formats the data to be added and calls script B,
formats the result and saves the html.

Script B is simply a 'remove tag' -function. It takes as arguments a
string, start string and end string.
It returns false if nothing was found&removed.
If start and end were found it returns an array:
temp[0]=trimmed_original_string, temp[1]=string_between_start_and_end

Everything worked fine when I developed this for plain html links. IOW,
no urls with '=' or '?'.

Now I need to call php script and pass variables and suddenly the
script B gets caught in infinite loop (stopped after 30 seconds).

Please help me out. I am really getting nowhere :cry:

Here is the script B.
To use it one needs to test if the result === "false" -> nothing replaced.
Else [0] and [1] are returned as mentioned above.

Code: Select all

&lt;?php

/* Funktio Poista (Function Remove)

	Searches and replaces the first string between $stralku and $strloppu (including arg strings).
   Etsii ja poistaa ensinmäisen alku- ja loppustringin välissä olevan osan kokostringistä,
   Palauttaa tulokset jonossa jossa &#1111;0] putsatun kokostringin ja &#1111;1] poistettu osa.
*/

function poista($kokostring, $stralku, $strloppu) { //args: string string, string start, string end

//etsitään alku
$ekstrak_alku = strpos($kokostring, $stralku);

if ($ekstrak_alku === false) { //oletettavasti alku ei löytynyt
	$poistofunktiojono&#1111;0] = ""; $poistofunktiojono&#1111;1] = "";
	return "false"; //ei löytynyt alkustringiä
}
//loppustringin pituus
$loppustr_pit = strlen($strloppu);

//kohta josta loppustring alkaa
$ekstrak_loppustringinalku = strpos($kokostring, $strloppu, $ekstrak_alku);

if ($ekstrak_loppustringinalku === false) {
	$poistofunktiojono&#1111;0] = ""; $poistofunktiojono&#1111;1] = "";
	return "false"; //ekstrak loppua ei löydy
}

//oletettavasti loppustring löytyi

	//koko stringin pituus
	$ekstrak_pituus = $ekstrak_loppustringinalku + $loppustr_pit - $ekstrak_alku;

	//poistettava string on
	$ekstrak_sisus = substr($kokostring, $ekstrak_alku, $ekstrak_pituus);

	//poistetaan string
	$poistofunktiojono&#1111;0] =  substr_replace ($kokostring, " ", $ekstrak_alku, $ekstrak_pituus); //REMOVES '=' and '?'
	//eregi_replace($ekstrak_sisus, ' ', $kokostring); //INFINITE LOOP
	$poistofunktiojono&#1111;1] = $ekstrak_sisus;

return $poistofunktiojono;

} //e_poista

?&gt;
:?:
jani
yjanni
Forum Newbie
Posts: 8
Joined: Wed May 22, 2002 3:17 pm

Post by yjanni »

note that I cannot use 'domain.net/script.php/variabl/value' type of urls
to call my scripts... :x
Post Reply