将动态参数传递给函数

I have a user defined function below:

function char_replace($line1){
    $line1= str_ireplace("Snippet:", "", $line1);
    // First, replace UTF-8 characters.
    $line1= str_replace(
    array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
    array("'", "'", '"', '"', '-', '--', '...'),
    $line1);
    // Next, replace their Windows-1252 equivalents.
    $line1= str_replace(
    array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
    array("'", "'", '"', '"', '-', '--', '...'),
    $line1);
}

and i'm replacing characters on multiple lines that i've exploded, except i want to apply a dynamic argument to the function char_replace where $line could very well be $line2 or $line3 so i would convert the characters this way: $line1 = char_replace($line1)

I want to make the function arguments and the str_replace/str_ireplace arguments to be a dynamic variable, where i could just convert another line like so: $random_line = char_replace($random_line) Is this possible?

Assuming that you end your function with return $line1; you can call it like this:

$line1 = char_replace($line1);
$line2 = char_replace($line2);
$line3 = char_replace($line3);

How you call the arguments in your function definition doesn't matter, they're local to that function and can have a different name outside of it.

If I'm reading this right, just add a return to the function. So:

function char_replace($string){
  $string= str_ireplace("Snippet:", "", $string);
  // First, replace UTF-8 characters.
  $string= str_replace(
  array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
  array("'", "'", '"', '"', '-', '--', '...'),
  $string);
  // Next, replace their Windows-1252 equivalents.
  $string= str_replace(
  array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
  array("'", "'", '"', '"', '-', '--', '...'),
  $string);

  return $string;
}

This will allow you to pass any string to the function and get the modified string back.

Do you just want to add return statement to your function:

function char_replace($line1){
    $line1= str_ireplace("Snippet:", "", $line1);
    // First, replace UTF-8 characters.
    $line1= str_replace(
    array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
    array("'", "'", '"', '"', '-', '--', '...'),
    $line1);
    // Next, replace their Windows-1252 equivalents.
    $line1= str_replace(
    array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
    array("'", "'", '"', '"', '-', '--', '...'),
    $line1);
    return $line1;
}